iPhone - JSON 解析中的转义字符问题

2024-01-12

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 .JSON response from the server

现在如果你观察这条线 "item_name" : "Spend$10andget$24worthofdonutsfromJim\'sDonutShop" ,有一个转义字符吉姆甜甜圈。我的解析器无法解析此异常。

 -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];

有人请帮助我!谢谢 !!


转义序列\'不是有效的 JSON。看json.org http://www.json.org/.

您应该向 Web 服务的维护者提出错误。

作为解决方法,您可以尝试用单个替换序列' e.g.

NSString* hackedString = [originalString stringByReplacingOccurrencesOfString: @"\\'" withString: @"'"];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

iPhone - JSON 解析中的转义字符问题 的相关文章

随机推荐