0

I have some NSData coming back from my server that is of type Json. I would like to know how to access the values present in the json and put them into there own NSString objects.

This is what the structure of the JsonArray looks like

enter image description here

This is the code I am using, however my for loop only ever shows "result" and nothing else.

NSError *error = nil;
    NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:csvData options: NSJSONReadingMutableContainers error: &error];
    NSLog(@"%@", jsonArray);
    if (!jsonArray) {
        NSLog(@"Error parsing JSON: %@", error);
    } else {
        for(NSDictionary *item in jsonArray) {
            NSLog(@"Item: %@", item);
        }
    }
1
  • 2
    It looks like your array contains dictionaries. And your dictionarys have a string as their key and another array as their value. Rest is up to you Commented Nov 26, 2013 at 8:48

3 Answers 3

2

You can access it like that:

for (NSDictionary *dict in jsonArray)
{
    NSLog(@"Data: %@", dict[@"result"]);
}

You have dictionary in your array so you have to enumerate is and access it by key (result, etc.).

Sign up to request clarification or add additional context in comments.

Comments

1
NSDictionary *resultDictionary = [jsonArray objectAtIndex: 0];
NSArray *resultArray = [resultDictionary objectForKey:@"result"];

for (NSString *item in resultArray)
{
    NSLog (@"item: %@",item);
}

You should add some (non)sense checking.

Comments

0

u can access the json array like this,

for(NSDictionary *Mydictionary in MyJsonArray) {
   Nsstring *DataOne = [Mydictionary objectforkey@"Mykey"];
}

For Cheking the json node u can put the json in this site and all the node will appear properly

http://json.parser.online.fr/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.