Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does RKNSJSONSerialization crash on iOS 6?

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?

like image 207
Josh Brown Avatar asked Oct 21 '22 16:10

Josh Brown


1 Answers

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?

like image 186
Josh Brown Avatar answered Nov 15 '22 03:11

Josh Brown