Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unescaped control characters in NSJSONSerialization

I have this JSON http://www.progmic.com/ielts/retrive.php that I need to parse. When I do it with NSJSONSerialization, I get "Unescaped control character around character 1981" error.

I need to know:

  • What the heck are the unescaped control characters? Is there a list or something?
  • How do I get rid of this error? The easiest way?

Thanks in advance.

like image 609
Umair Khan Jadoon Avatar asked Jun 24 '12 13:06

Umair Khan Jadoon


1 Answers

I added this method to remove the unescaped characters from retrieved string:

- (NSString *)stringByRemovingControlCharacters: (NSString *)inputString 
{ 
    NSCharacterSet *controlChars = [NSCharacterSet controlCharacterSet]; 
    NSRange range = [inputString rangeOfCharacterFromSet:controlChars]; 
    if (range.location != NSNotFound) { 
        NSMutableString *mutable = [NSMutableString stringWithString:inputString]; 
        while (range.location != NSNotFound) { 
            [mutable deleteCharactersInRange:range]; 
            range = [mutable rangeOfCharacterFromSet:controlChars]; 
        } 
        return mutable; 
    } 
    return inputString; 
} 

After recieving the NSData, I convert it to NSString, call the above method to get a new string with removed control characters and then convert the new NSString to NSData again for further processing.

like image 129
Umair Khan Jadoon Avatar answered Oct 01 '22 20:10

Umair Khan Jadoon