3

I did it easily in Android but Im little lost how to do it in iOs. My json is like:

[{"name":"qwe","whatever1":"asd","whatever2":"zxc"}, 
{"name":"fgh","whatever1":"asd","whatever2":"zxc"}]

If I do:

NSData *jsonData = [data dataUsingEncoding:NSUTF32BigEndianStringEncoding];

rows  = [NSJSONSerialization JSONObjectWithData: jsonData options: NSJSONReadingMutableContainers error: &error];

in rows can I access with?

NSString *name = [[rows objectAtIndex:0] [objectForKey:@s"name"]];

Or how I do that? thanks.

FINALLY NSString *name = [[rows objectAtIndex:0] objectForKey:@"name"]]; WORKS! :D

1
  • what did happen when you tried it? Commented Feb 15, 2013 at 10:27

3 Answers 3

3

I think that will work, however you want:

NSString *name = [[rows objectAtIndex:0] objectForKey:@"name"];

(dropped extraneous square brackets and use @"name" as string literal).

However, is the input JSON really in UTF-32 format?

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

Comments

2
NSMutableArray *row= [NSJSONSerialization JSONObjectWithData: jsonData options:        NSJSONReadingMutableContainers error: &error];
        for (int i=0; i<[row count]; i++) {
            NSMutableDictionary *dict=[row objectAtIndex:i];;
            NSString * name=[dict valueForKey:@"name"];
            NSLog(@"%@",name);
        }
    }

1 Comment

I am quite sure, that rowwon`t be a NSMutableArray.
2

Assuming the NSJSONSerialization operation was successful, simply:

NSString *name = rows[0][@"name"];

NSUTF32BigEndianStringEncoding is suspicious, json data is more usually NSUTF8StringEncoding.

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.