views:

237

answers:

1

http://github.com/gabriel/yajl-objc

I've already tried SBJSON, and while it works, I'm looking into alternative options to improve on parsing speed and memory consumption. Usage of this library doesn't seem to be as straightforward as SBJSON though, and I'm not sure how to begin using yajl.

Something like this:

NSArray *parsed = [data yajl_JSON];

Results in the following error:

-[NSConcreteMutableData yajl_JSON]: unrecognized selector sent to instance 0x5372180

Attempting to parse an NSString object results in the same problem. I can see the interface, but there doesn't seem to be an implementation... Am I not linking into the static lib properly?

Google turns up very little on usage examples. The doc on for the project itself only says the following about generating objects from json data/strings.

#import "NSObject+YAJL.h"

NSData *JSONData = [NSData dataWithContentsOfFile:@"example.json"];
NSArray *arrayFromData = [JSONData yajl_JSON];

NSString *JSONString = @"[\"Test\"]";
NSArray *arrayFromString = [JSONString yajl_JSON];

Which looks pretty much the same as what I've tried. What am I missing here?

A: 

You must have missed that part:

Under 'Other Linker Flags' in the Test target, add -ObjC and -all_load (So NSObject+YAJL category is loaded).

I had no problems with using YAJL, until I ran the app in Release mode, then I got the same error as you - turns out, I've only added these flags to Debug mode, not to all of them.

In general, I can recommend YAJL, it's definitely faster than all other alternatives (see benchmark results on my blog).

Psionides
Got it running. YAJL's output doesn't seem to match SBJSON's... Does YAJL always produce an array as an output even when the root object is a property list?
akaii