开发者

Why does this JSON fail only in iPhone?

开发者 https://www.devze.com 2022-12-22 18:22 出处:网络
I\'m using the JSON framework from http://code.google.com/p/json-framework. The JSON below fails with this error:

I'm using the JSON framework from http://code.google.com/p/json-framework. The JSON below fails with this error:

-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 being parsed:

[
    {
    "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"
    }
]

I think 0xd represents a carriage. When I put the above JSON in TextWrangler, I don't see any carriage returns. I got the JSON by doing "p开发者_C百科o myjson" in the debugger. It passes this validator: http://json.parser.online.fr/. Can anyone see what the problem may be?


You may well be getting bad data from the web service, or in an unexpected encoding. Using po myjson (or NSLog()) and then copy-pasting is going to omit any non-printable characters, so even if you do have a stray 0xd, the web-based validator isn't going to see it.

You should try something like [myjson rangeOfString:@"\15"] to check for the 0xd (octal 15 being equivalent to hex 0xd).

0

精彩评论

暂无评论...
验证码 换一张
取 消