iPhone - 解析charecter问题在JSON解析 [英] iPhone - Escape charecter issue in JSON parsing
问题描述
我正在使用客观的C JSON解析库并面临一些问题。我的Web服务返回JSON响应。当响应字符串中有转义字符时,我的解析器失败。以下是我从服务器收到的回复。
I am using objective C JSON parsing library and facing some issue . My web service returns the JSON response . My Parser fails when there is an escape character in the response string . Below is the response I am receiving from the server .
现在,如果观察者的行
item_name:花费$ 10andget $ 24worthofdonutsfromJim\'sDonutShop,则有一个转义字符 Jim \ Donut 。我的解析器无法解析这个异常。
Now if you observer the line "item_name" : "Spend$10andget$24worthofdonutsfromJim\'sDonutShop" , there is an escape character Jim\s Donut . My Parser fails to parse this with the 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}"
我使用的是 JSON.h
NSDictionary * responseDic = [responseString JSONValue];
有人请帮我!! hank你!!
Somebody please help me !! Thank you !!
推荐答案
转义序列 \'
不是有效的JSON。请参阅 json.org 。
The escape sequence \'
is not valid JSON. See json.org.
您应该向Web服务的维护者提出错误。
You should raise a bug with the maintainers of the web service.
作为一个工作,您可以尝试用单个'
替换序列,例如
As a work around, you might try replacing the sequence with a single '
e.g.
NSString* hackedString = [originalString stringByReplacingOccurrencesOfString: @"\\'" withString: @"'"];
这篇关于iPhone - 解析charecter问题在JSON解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!