Why does this JSON fail only in iPhone?
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).
加载中,请稍侯......
精彩评论