Jared Price
Jared Price

Reputation: 5375

Extracting data from nested NSDictionary's in a json array

I have a json array that I'm trying to extract data from. The array was created using NSJSONSerialization. Here is what the json array looks like from NSLog([jsonArray debugDescription]);:

{
    properties =     (
                {
            ID = 12345;
            PropertyName = "McDonalds";
            key = 00112233445566778899aabbccddeeff;
        },
                {
            ID = 12346;
            PropertyName = "Taco Bell";
            key = 00112233445566778899aabbccddeef0;
        },
                {
            ID = 12347;
            PropertyName = "Burger King";
            key = 00112233445566778899aabbccddeef1;
        }
    );
    success = 1;
    totalCount = 3;
}

I need to extract each ID and each Property name and dump the values into separate arrays. How can I do this?

Upvotes: 0

Views: 299

Answers (1)

Martin R
Martin R

Reputation: 540145

You can use Key-Value Coding:

NSArray *ids = [jsonArray valueForKeyPath:@"properties.ID"];
NSArray *propertyNames = [jsonArray valueForKeyPath:@"properties.PropertyName"];

Upvotes: 3

Related Questions