transfer contents of an NSDictionary to an NSArray
I successfully deserialise a JSON feed into a dic开发者_C百科tionary. Each dictionary item is an object with three properties. I would then like to transfer the contents to an NSArray using
self.array = [JSONdict allvalues];
but that puts the entire dictionary into the first array item. Where am I going wrong?
Thanks
I realised what was going wrong. I had to go one level up in the dictionary hierarchy and assign the dictionary itself, not the values in it. This works just fine:
self.array = [JSONdict valueForKey:@"members"];
Thanks for the comments and answers. And apologies for not using the right terms - my background is .Net
Check your NSDictionary instance JSONdict.
because if you read the documentation they have clearly stated.
Returns a new array containing the dictionary’s values.
- (NSArray *)allValues
Return Value
A new array containing the dictionary’s values, or an empty array if the dictionary has no entries.
I am not sure about how you want your data.
But if you want to group your values as per attributes in different arrays then you can use SBJSON Parser (or your existing JSON Parser in that case) to parse or deserialize your JSON feed as we can see here in the below code:
NSDictionary *myDict = [JSONFeed JSONValue];
NSMutableArray *DispName = [myDict valueForKey:@"DisplayName"];
NSMutableArray *IDArray = [myDict valueForKey:@"ID"];
NSMutableArray *URLArray = [myDict valueForKey:@"URL"];
Hope this helps you.
精彩评论