NSJSONSerialization fails to parse due to backslashes

42 Views Asked by At

The original text in the database is stuff stuff :o\.

My PHP server API is grabbing that and putting it into a json payload as this key:value pair:

"notetext": "stuff stuff :o\\",

My iOS objective-c code fetches the output of the server API with an NSURLSessionDataTask.

I parse the NSData object provided by the NSURLSessionDataTask like this:

NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];

I get the error: The data couldn’t be read because it isn’t in the correct format.

If I remove the backslash from the original text so that it is stuff stuff :o then everything works as expected. So the backslash at the end of the string seems to be causing my problem. But it looks like it is being escaped properly.

What am I missing? How do I make sure this can get parsed properly?

0

There are 0 best solutions below