2013-08-29 65 views
-4

我試圖用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代碼:JSON解析錯誤Objective-c

[ 
    { 
     "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當前沒有編碼?

+0

你的JSON沒有正常結束,驗證你的json在這裏 - jsonlint.org –

+2

也許缺少']'? –

+3

由於存在JSON短語和解析器,因此此問題似乎無關緊要。 –

回答

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/" 
    } 
] 

這應該工作分開。

+0

您可以使用http://jsonlint.com/驗證您的JSON –