Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I create array of retrieved JSON values in Xcode
    text
    copied!<p>I have a multiple JSON objects that I have to retrieve the value "title" for. I am successful in retrieving each of the "title" values, however, I am not sure how I can put all these title values into an <code>NSMutableArray</code> that I can later populate a <code>UITableView</code> with. </p> <p>Currently, storyTitle (a <code>NSString</code>) returns several different strings, but they are all separate. For example, the console returns</p> <pre><code>2013-03-30 21:39:30.416 Appv0.1[32742:11303] ( "Boys\U2019 lacrosse display drive at Watsonville Jamboree" ) 2013-03-30 21:39:31.799 Appv0.1[32742:11303] ( "Volleyball teams currently undefeated midway through season" ) 2013-03-30 21:39:32.093 Appv0.1[32742:11303] ( "Wrestling season ends with a CCS victory and 2 state berths" ) </code></pre> <p>How do I combine these strings into an array? Thanks in advance! Any help would be appreciated.</p> <pre><code>NSDictionary *res = [NSJSONSerialization JSONObjectWithData: returnData options:NSJSONReadingMutableLeaves error:&amp;myError]; storyList = [NSMutableArray alloc]; storyTitle = [res objectForKey:@"title"]; //create array of storyTitles NSString * story1 = [NSString stringWithFormat:@"%@", storyTitle]; //not sure how to do this array part storyList = [NSMutableArray arrayWithObjects:story1,nil]; </code></pre> <p><strong>Edit:</strong> If I do:</p> <pre><code> for(int i = 0; i &lt; 5; i++){ storyTitle = [res objectForKey:@"title"]; NSString * story1 = [NSString stringWithFormat:@"%@", storyTitle]; [self.storyList addObject:story1]; } </code></pre> <p>Console returns </p> <pre><code>array: ( "Boys\U2019 lacrosse display drive at Watsonville Jamboree", "Boys\U2019 lacrosse display drive at Watsonville Jamboree", "Boys\U2019 lacrosse display drive at Watsonville Jamboree", "Boys\U2019 lacrosse display drive at Watsonville Jamboree", "Boys\U2019 lacrosse display drive at Watsonville Jamboree",) </code></pre> <p>How do I make the array have all 3 separate stories? </p>
 

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