Search code examples
iphoneobjective-ciosipadsbjson

SBJson parse attempt -- objective C


I'm trying to parse the following JSon (which was validated I think last time I checked):

{
    "top_level" =     (
                {
            "download" = "http:/target.com/some.zip";
            "other_information" = "other info";
            "notes" =             (
                                {
                    obj1 = "some text";
                    obj2 = "more notes";
                    obj3 = "some more text still";
                }
            );
            title = "name_of_object1";
        },
                {
            "download" = "http:/target.com/some.zip";
            "other_information" = "other info";
            "notes" =             (
                                {
                    obj1 = "some text";
                    obj2 = "more notes";
                    obj3 = "some more text still";
                }
            );
            title = "name_of_object2";
        },
                {
            "download" = "http:/target.com/some.zip";
            "other_information" = "other info";
            "notes" =             (
                                {
                    obj1 = "some text";
                    obj2 = "more notes";
                    obj3 = "some more text still";
                }
            );
            title = "name_of_object3";
        }
    );
}

My attempt is using the following:

NSDictionary *myParsedJson = [myRawJson JSONValue];

for(id key in myParsedJson) {
    NSString *value = [myParsedJson objectForKey:key];
    NSLog(value);
}

Error:

-[__NSArrayM length]: unrecognized selector sent to instance 0x6bb7b40

Question: It seems to me that JSon value makes myParsedJson object an NSArray instead of a NSDictionary.

How would I iterate through the objects called name_of_object and access each of the nested dictionaries? Am I going about it the right way?


Solution

  • The first argument of NSLog must be a string. Try this:

    NSLog(@"%@", value);