Reputation: 1110
I am trying to correctly target the elements within the Json Output and I am getting closer but I presume there is a easy and obvious way I am missing.
My Json looks like this with a upper level event.
JSON SNIPPET UPDATED
chat = (
(
{
Key = senderId;
Value = {
Type = 0;
Value = "eu-west-1:91afbc3f-890a-4160-8903-688bf0e9efe8";
};
},
{
Key = chatId;
Value = {
Type = 0;
Value = "eu-west-1:be6457ce-bac1-412d-9307-e375e52e22ff";
};
},
{
Key = timestamp;
Value = {
Type = 1;
Value = 1430431197;
};
},
//Continued
I am targeting this level using
NSArray *chat = array[@"chat"];
for ( NSDictionary *theCourse in chat )
{
NSLog(@"---- %@", theCourse);
// I tried the following to target the values
//NSLog(@"chatId: %@", [theCourse valueForKey:@"Key"]);
//NSLog(@"timestamp: %@", theCourse[@"senderId"] );
}
}
I need to parse the value data for each key which if I was using an array would do like [theCourse valueForKey:@"Key"]
but I think I may not be going deep enough?
As you would expect, [theCourse valueForKey:@"Key"]
gives me the Key values but I need the associate values of those keys.
Upvotes: 1
Views: 80
Reputation: 4140
You can create an easier dictionary:
NSArray *chat = array[@"chat"][0];
NSMutableDictionary* newDict = [NSMutableDictionary dictionary];
for (NSDictionary* d in chat)
[newDict setValue:d[@"Value"][@"Value"] forKey:d[@"Key"]];
Now you can use the newDict
.
NSLog(@"chatId: %@", [newDict valueForKey:@"chatId"]);
Upvotes: 1