0

I have used JSONKit library to parse dictionary and get JSON string. All is well and good with normal devices (iOS7). But when i run application in iOS 7-64 bit simulator it was crashed at below method:

- (NSString *)JSONString;

And the crash message shows on this line of JSONKit.m class

enter image description here

Tried to find out it but not able to sort out.

And i ended up with our native NSJSONSerialization class.

Did any one sort out this?

Kampai
  • 22,848
  • 21
  • 95
  • 95

2 Answers2

4

As far as I know there are more than one patch versions that tried to fix the 64 bit crash issue you mention here, e.g. JSONKit 64bit crash fix by heroims.

They all tried to fix that troublesome line for getting tagged pointers, "the very first thing that a pointer to an Objective-C object "points to" is a pointer to that objects class":

*((void **)objectPtr) 

I wrote a simple code to emulate the crash,

NSDictionary *dic = @{@"hi":@(4)};
void *keys[2], *objects[2];
CFDictionaryGetKeysAndValues((CFDictionaryRef)dic, (const void **)keys, (const void **)objects);
void *objectPtr = objects[0];
void *another = *((void **)objectPtr);//Only works for 32 bit machine
NSLog(@"%@",[another description]);

My guess is that for 64bit compiler, apple changed the tagged pointer implementation for NSNumber, which causes the crash. Check the discussion for tagged pointers here stackoverflow.com/questions/5819387/why-is-nsnumber-immutable

If I change NSDictionary *dic = @{@"hi":@(4)}; to NSDictionary *dic = @{@"hi":@"hello"}; it won't crash.

The patch I mentioned here just used object_getClass, which seems to defeat the original purpose, "Why not just use object_getClass()?..." (the comments right above)

So like you said now I also end up using NSJSONSerialization class.

Community
  • 1
  • 1
Qiulang
  • 10,295
  • 11
  • 80
  • 129
2

There is an patched version of JSONKit here that fixes the 64 bit issues among others.