Igor Camilo Igor Camilo - 4 months ago 53x
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]);


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