Writing an iPhone app, and I’m getting my data from a REST API that returns JSON. My problem is, some of the data has special characters embedded and I’m getting errors. Example:
MartÌn
Petite-RiviËre-Saint-FranÁois
Here is my current code:
NSString *jsonString = [[NSString alloc]
initWithData:receivedData
encoding:NSUTF8StringEncoding];
NSMutableArray *tempResults = [[[jsonString JSONValue]
objectForKey:@"getRegionResortsLastUpdatedResponse"]
objectForKey:@"return"];
Whenever the data has special characters in it "jsonString" return "(null)", otherwise everything works fine.
Is this something I can handle on my end, or does the API need to be modified to output the character codes?
If
-initWithData:encoding:returns nil, your data is almost certainly not encoded in the requested encoding. I suspect you’re not sending UTF8, and are rather sending some other encoding such as one of the Windows code pages or Latin1. See String Encoding in the NSString documentation.