2013-02-16 2 views
12

이 지난 10 시간 동안 충돌을 디버깅하기 위해 노력하고 그리고 마지막으로, 나는이 코드를 단순화 : NSZombieEnabled와NSJSONSerialization 버그?

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

,이 (파싱이 발생) 세 번째 줄에서 응용 프로그램을 충돌하고 그것을 기록 : payload.txt

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

내용은 다음과 같습니다

[ 
    { 
     "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 
    } 
] 

그것은이 개 사전의 배열 그냥. 이 충돌을 일으키는 원인이 무엇인지 /이 JSON의 문제점은 확실하지 않습니다.

업데이트 배열의 첫 번째 개체에서 "is_subscribed":0을 제거하면 충돌이 제거됩니다.

+0

보다 SBJSON 라이브러리를 사용하려고하면 쉽습니다. – Dilip

+1

@Dilip SBJSON을 사용하고 싶지 않습니다. 왜 NSJSONSerialization이 충돌하고 JSON에 문제가 있는지 알고 싶습니다. – 0xSina

+5

@Dilip 나쁜 조언을하지 마십시오. –

답변

3

정상적인 nil 결과 및 오류 변수가 채워지지 않고 충돌 사고가 발생하기 때문에 Apple이 해당 클래스의 오류 처리에서 나쁜 작업을 한 것처럼 보입니다. 귀하의 json 데이터와 최소한의 코드는 Apple이 적절한 버그 리포트를 위해 보통 요구하는 것입니다. 링크를 따라 버그를보고하십시오 - https://developer.apple.com/bugreporter/ zip에서 프로젝트를 충돌하는 증거로 첨부하는 것을 잊지 마십시오.

+0

중복 된 vars의 논리가 무엇인지 btw를 명확하게 설명해 주시겠습니까? 어떻게 처리 할 계획인지 잘 모릅니다. –

+0

문제는 단순히 중복 된 키가 아니라 "is_subscribed"문자열 키입니다. 사실, 주 배열에서 두 개의 사전 주위를 순서대로 바꾸면 더 이상 충돌이 발생하지 않으므로 단순히 중복 된 키 이상입니다. 더 많은 것을 위해 주요 포스트의 밑에 토론을 읽으 십시요. '[{ "key": 0, "key": 0}]'이 문제를 일으키지 않습니다. 메인 포스트에 대한 토론을 읽으면 사전에 중복 된 키의 논리를 발견 할 수 있습니다 ... 서버 측에서 실수로 저의 실수였습니다. – 0xSina

+1

당신 말이 맞아요. 나는 일련의 시험을 겪었고 단지 하나의 이상한 행동 만있는 것으로 보인다. 나는 당신이 버그 보고서에 대한 좋은 사례가 있다고 생각합니다. 예상되는 동작이 아니므로 이러한 클래스는 모든 설정에서 충돌하지 않아야합니다. 귀하는 다음 링크 (https://developer.apple.com/bugreporter/)를 통해 보고서를 제출할 수 있습니다. –

1

이 문제가 있으며 저에게이 문제는 JSON의 중복 키였습니다. 내 키의 이름이 다르게 지정되었습니다. 예를 들어 'is_subscribed'가 아니라 'food_nutrients'입니다. 그 사이에 또 ​​다른 키가있는 중복 키에 iOS 6이 충돌 할 확률이 높습니다. 일부 의견은 "is_subscribed"키가 아닙니다.

모든 이름의 중복 키가 문제가되는 것으로 확인되었습니다. 관련 : https://stackoverflow.com/a/21148319/2030