Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I parse array JSON in objective-c

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

like image 976
ƒernando Valle Avatar asked Aug 04 '26 12:08

ƒernando Valle


1 Answers

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?

like image 199
trojanfoe Avatar answered Aug 07 '26 05:08

trojanfoe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!