Why does RKNSJSONSerialization crash on iOS 6?

五迷三道 提交于 2019-12-10 14:18:17

问题


I'm seeing a crash in RKNSJSONSerialization on iOS 6 only - not on iOS 7. I'm using RestKit 0.20.3 and it happens fairly consistently for me. Even when I make the same request and get the same response for iOS 6/7, it works fine on iOS 7 but crashes on iOS 6.

Here's the crash - it's an EXC_BAD_ACCESS: http://crashes.to/s/2610b639062

The relevant (crashing) line in RestKit's RKNSJSONSerialization is the return:

+ (id)objectFromData:(NSData *)data error:(NSError **)error
{
    return [NSJSONSerialization JSONObjectWithData:data options:0 error:error];
}

So perhaps it's not RestKit at all - perhaps it's NSJSONSerialization.

I profiled the app with the Zombies tool and found this:

"An Objective-C message was sent to a deallocated 'CFString (immutable)' object (zombie) at address: 0x16851250."

Am I doing something wrong?


回答1:


I've resolved this. The issue was that my JSON had duplicate keys in it, and iOS 6 couldn't handle that. The solution is to remove the duplicate keys from the JSON before trying to parse it with NSJSONSerialization on iOS 6. Apparently Apple has resolved this issue on iOS 7, since it doesn't crash there.

Related: NSJSONSerialization bug?




回答2:


This seems to be a typo.

Assuming there is an object called error of type NSError, the call JSONObjectWithData: takes a pointer to a pointer as the last argument, i.e. with &.

return [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];


来源:https://stackoverflow.com/questions/21122740/why-does-rknsjsonserialization-crash-on-ios-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!