IPhone - Escape charecter problem in parsing JSON

I use the JSON parsing object library and run into some problems. My web service returns a JSON response. My parser does not work when there is an escape character in the response line. Below is the answer I get from the server.JSON response from the server

Now, if you watch the line "item_name": "Spend $ 10 and $ 24worthofdonutsfromJim \ 'sDonutShop", there is an escape character Jim \ s Donut . My Parser cannot analyze this with an exception.

 -JSONValue failed. Error trace is: (
    "Error Domain=org.brautaset.JSON.ErrorDomain Code=8 \"Illegal escape sequence '0x27'\" UserInfo=0x79cc420 {NSLocalizedDescription=Illegal escape sequence '0x27'}",
    "Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Object value expected for key: item_name\" UserInfo=0x79cc510 {NSUnderlyingError=0x79cc470 \"Illegal escape sequence '0x27'\", NSLocalizedDescription=Object value expected for key: item_name}",
    "Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Object value expected for key: parameters\" UserInfo=0x79cc5c0 {NSUnderlyingError=0x79cc540 \"Object value expected for key: item_name\", NSLocalizedDescription=Object value expected for key: parameters}"

All I use is JSON.h

NSDictionary * responseDic = [responseString JSONValue];

Someone please help me !! Thank!

+3
source share
1 answer

\' JSON. . json.org.

-.

, ' .

NSString* hackedString = [originalString stringByReplacingOccurrencesOfString: @"\\'" withString: @"'"];
+5

All Articles