title: How to retrieve an item ID from an item from JSON
body: <p>I'm using a web service that returns food menu items to me from a variety of restaurants. Once a user enters a restaurant name and clicks the "search" button, the user is directed to a table view populated with menu items. </p>
  
  <p>Here is the code that retrieves the data from the service (probably irrelevant for now, but could come in use for your guys' answers)
  :</p>
  
  <pre><code>  NSString *userString = [userEnteredText text];
      NSString *correctedString = [userString stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
  
      NSString *urlString = [NSString stringWithFormat:@"https://api.nutritionix.com/v1_1/search/%@?results=0%%3A20&amp;cal_min=0&amp;cal_max=50000&amp;fields=item_name%%2Cbrand_name%%2Citem_id%%2Cbrand_id&amp;appId=MY_APP_ID&amp;appKey=MY_APP_KEY", correctedString];
  
      NSURL *url = [NSURL URLWithString:urlString];
  
      NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url
                                                  cachePolicy:NSURLRequestReturnCacheDataElseLoad
                                              timeoutInterval:30];
  
      NSData *urlData;
      NSURLResponse *response;
      NSError *error;
  
  
      urlData = [NSURLConnection sendSynchronousRequest:urlRequest
                                      returningResponse:&amp;response
                                                  error:&amp;error];
  
      NSMutableDictionary *foodDataArray = [NSJSONSerialization JSONObjectWithData:urlData options:kNilOptions error:&amp;error];
  
      NSMutableDictionary *items = [foodDataArray objectForKey:@"hits"];
  
      NSMutableArray *fields = [items valueForKey:@"fields"];
  
      itemNamesArray = [fields valueForKey:@"item_name"];
  </code></pre>
  
  <p>Just like how I retrieved "item_name", I can retrieve an array of "item_id".</p>
  
  <p>When the user clicks on a menu item, I want to retrieve that item's id and plug it into the service to retrieve the nutritional facts of that menu item.</p>
  
  <p>I tried the following:</p>
  
  <p>This is in my prepareForSegue method where "MVC" is my destination View Controller.</p>
  
  <pre><code>  theItemIDArray = [fields valueForKey:@"item_id"];
    [MVC setItemIDArray:theItemIDArray];
  </code></pre>
  
  <p>Then in my MVC.m I have this code:</p>
  
  <pre><code>-(void)setItemIDArray:(NSMutableArray *)b
  {
  theitemIDArray = b;
  }
  </code></pre>
  
  <p>As you can see, I'm passing my array of itemID's from my original view controller to my destination view controller.</p>
  
  <p>Here comes the part where I have to pass in an item ID in order to get that item's nutritional info.</p>
  
  <p>In my prepareForSegue on my destination view controller, I attempt to pass in the array like so:</p>
  
  <pre><code>NSString *urlString = [NSString stringWithFormat:@"https://api.nutritionix.com/v1_1/item?id=%@&amp;appId=MY_APP_ID&amp;appKey=MY_APP_KEY", theitemIDArray];
  </code></pre>
  
  <p>However, this urlString requires me to pass in an NSString, not an NSMutableArray.</p>
  
  <p>So my question is: How can I retrieve the itemID of the cell I clicked on and plug in that ID to return the nutritional info?</p>
  
  <p>Sorry for the lengthy format and abundance of code, but I've been at this issue for hours with no glimpse of success.</p>