How do I get a JSON and store in a list?

Asked

Viewed 50 times

0

I would like to receive a JSON that contains several messages and stores it in a list that contains one JSON content per position

The JSON format would be this:

[{"id":"42","data":"02\/12\/2015 12:01:21","texto":"blablabla","nome":null},
 {"id":"48","data":"02\/12\/2015 12:02:21","texto":"kkkkkkk","nome":fulano},
 {"id":"29","data":"03\/12\/2015 12:02:21","texto":"hi ha ho","nome":jhonn}]

At Xcode, I’m working with Objective-C.

1 answer

2


First you need to convert this string for a NSData:

NSData *data = [json dataUsingEncoding:NSUTF8StringEncoding];

And then, for a NSArray, which is a list of NSDictionary:

NSError *error;
NSArray *array = [NSJSONSerialization JSONObjectWithData: data options: nil error: &error];

Browser other questions tagged

You are not signed in. Login or sign up in order to post.