JSON解析错误Objective-c

时间:2013-08-29 08:52:34

标签: objective-c json

我尝试使用NSJSONSerialization解析JSON。 NSArray *a = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&err];错误显示:Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Badly formed array around character 202.) UserInfo=0x9f79230 {NSDebugDescription=Badly formed array around character 202.} 这是JSON代码:

[
    {
        "ID":1,
        "name":"sometext",
        "c":"sometext",
        "city":"sometext",
        "street":"sometext",
        "a":32.914671,
        "b":35.292417,
        "Info":"sometext",
        "imageAddress":"images/aroma.jpeg"
    }
    {
        "ID":2,
        "name":"sometext",
        "c":"sometext",
        "city":"sometext",
        "street":"sometext",
        "a":4.224,
        "b":72.1234,
        "Info":"sometext",
        "imageAddress":"images/"
    }

当前JSON没有编码?

1 个答案:

答案 0 :(得分:1)

在您的JSON中,数组对象不会被comma

分隔
[
    {
        "ID":1,
        "name":"sometext",
        "c":"sometext",
        "city":"sometext",
        "street":"sometext",
        "a":32.914671,
        "b":35.292417,
        "Info":"sometext",
        "imageAddress":"images/aroma.jpeg"
    },
    {
        "ID":2,
        "name":"sometext",
        "c":"sometext",
        "city":"sometext",
        "street":"sometext",
        "a":4.224,
        "b":72.1234,
        "Info":"sometext",
        "imageAddress":"images/"
    }
]

这应该有用。