Igor Camilo Igor Camilo - 1 year ago 108
JSON Question

NSJSONSerialization JSONObjectWithData:options:error: encoding issue

In my code, I download a

data encoded in
, which is the ideal to work with
, but when I get the parsed object, it's full of encoding problems such as:

"Jo\U00e3o e Maria - Ca\U00e7adores de Bruxas"

(it must be "João e Maria - Caçadores de Bruxas"). Tried to reencode it in ASCII, Unicode and others with no success:

NSData *downloadedData = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:requestURL cachePolicy:cachePolicy timeoutInterval:timeoutInterval] returningResponse:NULL error:&error];
NSDictionary *serializedDictionary = [NSJSONSerialization JSONObjectWithData:downloadedData options:NSJSONReadingAllowFragments error:&error];

EDIT: When I print using this, it shows correctly:

NSLog(@"Test: %@", [[NSString alloc] initWithData:downloadedData encoding:NSUTF8StringEncoding]);

Answer Source

Those are UTF8 encoded characters. The format is correct, put them on a UILabel or something and they'll appear as you expect.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download