Vlad Z.
Vlad Z.

Reputation: 3451

Can't parse json Data via YAJLiOS

At first i'm trying to access local file in my app folder:

    NSData *data = [NSData dataWithContentsOfFile:
                                      [@"countries.json" stringByExpandingTildeInPath]];

result is always NULL

then i tried to check is file exists:

    NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString* foofile = [documentsPath stringByAppendingPathComponent:@"countries.json"];
    BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:foofile];

it doesn't exist, and i use following code to access my json file:

    NSString *data1 = [[NSBundle mainBundle] pathForResource:@"countries" ofType:@"json"];
    NSData *data2 = [[NSData alloc] initWithContentsOfFile:data1];

it getting the file but when i try to parse it:

    NSDictionary *dict1 =[data2 yajl_JSON];

i getting an error:

    [NSConcreteData yajl_JSON]: unrecognized selector sent to instance 0x6838d60

My questions is next:


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

Screenshot of my Xcode Build Phases:

enter image description here

Upvotes: 4

Views: 373

Answers (1)

Till
Till

Reputation: 27597

According to the YAJL documentation the method you are trying to invoke does in fact exist.

That leaves only one option; you have not fully linked against the YAJL framework.

Make sure it shows up within the list of linked frameworks/libraries of your App target just like CFNetwork.framework shows up in my example.

enter image description here

Since the method you are trying to invoke is in fact part of a category on NSData, make sure you include -ObjC in your Other Linker Flags.

enter image description here

From Apple's Technical Q&A.

This flag causes the linker to load every object file in the library that defines an Objective-C class or category. While this option will typically result in a larger executable (due to additional object code loaded into the application), it will allow the successful creation of effective Objective-C static libraries that contain categories on existing classes.

Upvotes: 3

Related Questions