objective c - iPhone NSArray from Dictionary of Dictionary values -


I have a dictionary of dictionaries that is coming back to me in JSON format

  "Never": {"color": 0, "count": 0, "UID": 32387, "id": 73129, "name": "never"}, "dev": {"color" : ",": ",", "Id": 32387, "id": 72778, "name": "dev"}, "iphone": {"color": 0, "count": 1, "uid" : 32387, id ": 72777," name ":" iphone "}}  

I also have an NSArray that has the required ID for an item such as [72777, 7312 9]

What do I need to do, id => no for objects in the array I get a dictionary of. I know that it is possible through the array again, and then it is to loop through the values ​​of checking the dictionaries and values, but it seems that this is a less long

Excuse me, I just want to find my way around the iPhone SDK and learn the purpose and the coco.

First of all, since you have a JSON Using, I hope you have already met and / or, you are open-source projects to parse both JSON in native Coco formations. Returns an idea about how to use the latter to obtain NSDictionary from a JSON string.

The problem then becomes one in finding the values ​​matched in the dictionary. I do not know about a method that you are looking for - cocoa frameworks are very powerful, but they are designed to be very general and flexible. However, it should not be very difficult to put together in many lines ... (Since you are programming on the iPhone, I will use fast calculation to make the code cleaner.)

 < Code> NSDictionary * jsonDictionary = ... NSDrift * Director; NSArray * Required ID = ... NSMutableDictionary * matches = [NSMutableDictionary dictionary]; For (id key in jsonDictionary) {innerDictionary = [jsonDictionary objectForKey: key]; If the [include the required ID: Object: [internal object fork: @ "id"]]) [with set object: [innerDictionary objectForKey: @ "name"] for that: [innerDictionary objectForKey: @ "id"] ]; }  

This code may contain typo, but the concepts should be sound. Also keep in mind that calls [NSMutableDictionary dictionary] to call an autorelase object.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -