为什么这个JSON只在iPhone中失败?

时间:2010-03-15 01:56:12

标签: iphone objective-c cocoa-touch json

我正在使用http://code.google.com/p/json-framework中的JSON框架。下面的JSON失败并出现此错误:

-JSONValue failed. Error trace is: (
Error Domain=org.brautaset.JSON.ErrorDomain Code=5 UserInfo=0x124a20 "Unescaped control character '0xd'",
Error Domain=org.brautaset.JSON.ErrorDomain Code=3 UserInfo=0x11bc20 "Object value expected for key: Phone",
Error Domain=org.brautaset.JSON.ErrorDomain Code=3 UserInfo=0x1ac6e0 "Expected value while parsing array"

正在解析JSON:

[
    {
    "id" :"2422",
    "name" :"BusinessA",
    "address" :"7100 U.S. 50",
    "lat" :"38.342945",
    "lng" :"-90.390701",
    "CityId" :"11",
    "StateId" :"38",
    "CategoryId" :"1",
    "Phone" :"(200) 200-2000",
    "zip" :"00010"
    }
]

我认为0xd代表一个马车。当我在TextWrangler中放置上面的JSON时,我没有看到任何回车。我通过调试器中的“po myjson”得到了JSON。它通过了这个验证器:http://json.parser.online.fr/。任何人都可以看到问题所在吗?

1 个答案:

答案 0 :(得分:1)

您可能会从Web服务或意外编码中获取错误数据。使用po myjson(或NSLog())然后复制粘贴将省略任何不可打印的字符,所以即使你有一个迷路0xd,基于网络的验证器也不会看到它

你应该尝试[myjson rangeOfString:@"\15"]之类的东西来检查0xd(八进制15相当于十六进制0xd)。