1

This is a followup question to this In short, I'm making my app iOS 4.3 compatible and using the AFNetworking class version 0.10.1 that supports iOS 4 in my app. This line self.responseJSON = AFJSONDecode(self.responseData, &error); gives me the error bellow. I'm not really familiar with JSON and trying to figure out what this error means.

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** - [JKDictionary allocWithZone:]: The JKDictionary class is private to JSONKit and should not be used in this fashion.'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x006ef5a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x018e6313 objc_exception_throw + 44
    2   CoreFoundation                      0x006a7ef8 +[NSException raise:format:arguments:] + 136
    3   CoreFoundation                      0x006a7e6a +[NSException raise:format:] + 58
...
...
26  libdispatch_sim.dylib               0x02888289 _dispatch_call_block_and_release + 16
27  libdispatch_sim.dylib               0x0288acb4 _dispatch_queue_drain + 250
28  libdispatch_sim.dylib               0x0288b2c2 _dispatch_queue_invoke + 49
29  libdispatch_sim.dylib               0x0288b593 _dispatch_worker_thread2 + 261
30  libsystem_c.dylib                   0x90093b24 _pthread_wqthread + 346
31  libsystem_c.dylib                   0x900956fe start_wqthread + 30

The error is from JSONKit.m:

+ (id)allocWithZone:(NSZone *)zone
{
#pragma unused(zone)
    [NSException raise:NSInvalidArgumentException format:@"*** - [%@ %@]: The %@ class is private to JSONKit and should not be used in this fashion.", NSStringFromClass([self class]), NSStringFromSelector(_cmd), NSStringFromClass([self class])];
    return(NULL);
}

With iOS 5 the app is using the line self.responseJSON =[NSJSONSerialization JSONObjectWithData:self.responseData options:0 error:&error]; that works great but ofcourse I can't use this in iOS 4 because NSJSONSerialization isn't supported.

James Risner
  • 5,451
  • 11
  • 25
  • 47
Segev
  • 19,035
  • 12
  • 80
  • 152
  • Is `[JKDictionary alloc]` anywhere in your project? – Carl Veazey Jan 02 '13 at 07:51
  • No. Where should I place it? – Segev Jan 02 '13 at 07:55
  • The problem is somewhere in your code you are calling `alloc` on `JKDictionary` when you shouldn't be, so was hoping you'd be able to find out where that part of your code was. – Carl Veazey Jan 02 '13 at 07:57
  • The only line I see related to your suggestion is `if((dictionary = [[JKDictionary alloc] init]) == NULL) { return(NULL); }` inside `JSONKit.m`. But I'm guessing that's not what you are looking for. – Segev Jan 02 '13 at 08:00
  • Which version of JSKONKit are you using, I don't see that in the version on github. Does using the latest version of JSONKit help? – Carl Veazey Jan 02 '13 at 08:08
  • I'm using the latest version. v2.0 – Segev Jan 02 '13 at 08:20
  • The latest tagged version of JSONKit is v1.4, but that's quite a bit older than the latest change on the master branch. The most similar line to the one in your comment that I see on master is from [Line 932 in JSONKit.m](https://github.com/johnezang/JSONKit/blob/master/JSONKit.m#L932): `if((dictionary = [dictionary init]) == NULL) { return(NULL); }`. Did you get your copy of the source from the same place? – David Alber Jan 02 '13 at 09:29
  • I wasn't the one started this app. Here: https://github.com/johnezang/JSONKit/blob/master/JSONKit.h you can see in the first lines of the file that the version is 2.0 – Segev Jan 02 '13 at 09:52
  • That's the Apache License version number. – Nate Chandler Jan 02 '13 at 13:41
  • You are right. I've downloaded the latest version. I'm still getting the same error.It's always _responseJSON id 0x00000000 – Segev Jan 02 '13 at 16:33

1 Answers1

0

I ended up replacing the problematic line with this self.responseJSON = [[CJSONDeserializer deserializer] deserialize:self.responseData error:&error];

Used a different class (TouchJSON) just for that line but it works great now.

Segev
  • 19,035
  • 12
  • 80
  • 152