Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First off, since you're using JSON, I'm hoping you've already found <a href="http://github.com/blakeseely/bsjsonadditions/" rel="nofollow noreferrer">BSJSONAdditions</a> and/or <a href="http://code.google.com/p/json-framework/" rel="nofollow noreferrer">json-framework</a>, both of them open-source projects for parsing JSON into native Cocoa structures for you. <a href="http://zachwaugh.com/2009/01/how-to-use-json-in-cocoaobjective-c/" rel="nofollow noreferrer">This blog post</a> gives an idea of how to use the latter to get an NSDictionary from a JSON string.</p> <p>The problem then becomes one of finding the matching values in the dictionary. I'm not aware of a single method that does what you're looking for — the Cocoa frameworks are quite powerful, but are designed to be very generic and flexible. However, it shouldn't be too hard to put together in not too many lines... (Since you're programming on iPhone, I'll use fast enumeration to make the code cleaner.)</p> <pre><code>NSDictionary* jsonDictionary = ... NSDictionary* innerDictionary; NSArray* requiredIDs = ... NSMutableDictionary* matches = [NSMutableDictionary dictionary]; for (id key in jsonDictionary) { innerDictionary = [jsonDictionary objectForKey:key]; if ([requiredIDs containsObject:[innerDictionary objectForKey:@"id"]]) [matches setObject:[innerDictionary objectForKey:@"name"] forKey:[innerDictionary objectForKey:@"id"]]; } </code></pre> <p>This code may have typos, but the concepts should be sound. Also note that the call to <code>[NSMutableDictionary dictionary]</code> will return an autoreleased object.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload