13

過去10時間クラッシュをデバッグしようとしていて、最後に、次のコードに簡略化しました。

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

NSZombieEnabledを使用すると、3行目(解析が行われる場所)でアプリがクラッシュし、次のログが記録されます。

*** -[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://cdn.steampowered.com/v/gfx/apps/2340/header_292x136.jpg",
      "is_subscribed":0,
      "link":"http://store.steampowered.com/app/2340/",
      "price":"4.99",
      "seller_id":2,
      "thumb":"http://media.steampowered.com/steamcommunity/public/images/apps/2340/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://cdn.steampowered.com/v/gfx/apps/2310/header_292x136.jpg",
      "is_subscribed":0,
      "link":"http://store.steampowered.com/app/2310/",
      "price":"9.99",
      "seller_id":2,
      "thumb":"http://media.steampowered.com/steamcommunity/public/images/apps/2310/e5bdf8dc7759c573fe525d45b69011f6a173a984.jpg",
      "title":"Quake",
      "updated_at":"2013-02-15T23:45:59-05:00",
      "is_subscribed":0
   }
]

これは、2つの辞書の配列にすぎません。このクラッシュの原因/このJSONの何が問題になっているのかわかりません。

UPDATE配列の最初のオブジェクトを削除"is_subscribed":0すると、クラッシュが解消されます。

4

2 に答える 2

3

通常のnilの結果とエラー変数が入力される代わりにクラッシュするため、Appleはクラス内のそのようなケースのエラー処理で悪い仕事をしたようです。jsonデータと最小限のコードは、Appleが適切なバグレポートに通常必要とするものです。次のリンクでバグを報告してください-https: //developer.apple.com/bugreporter/クラッシュの証拠として、プロジェクトをzip形式で添付することを忘れないでください。

于 2013-02-16T23:15:12.343 に答える
1

私はこの問題を抱えていました。私にとって、問題は JSON の重複キーでした。私のキーは別の名前でした-あなたの場合のように「is_subscribed」ではなく、「food_nutritions」です。いくつかのコメントが示唆しているように、「is_subscribed」キーだけでなく、その間に別のキーがある重複キーで iOS 6 がクラッシュすることは間違いありません。

任意の名前の重複キーが問題であることを確認しました。関連: https://stackoverflow.com/a/21148319/2030

于 2014-01-15T21:08:15.713 に答える