Convert String(already formatted) to an Array of NSDictionary

66 views Asked by At

I have this String already formatted as a [[String:AnyObject]], however I can't retrieve the information out of it nor couldn't find a way to convert it to a dictionary.

[ [name: Laura, age:33, gender: female], [name: James, age:25, gender:male] ]

What can be done to convert this string into a dictionary?

1

There are 1 answers

0
Nekak Kinich On BEST ANSWER

Your formatted string must be well formatted as an json, then you can use the next code:

NSString* str=@"[ {\"name\": \"Laura\", \"age\":33, \"gender\": \"female\"}, {\"name\": \"James\", \"age\":25, \"gender\":\"male\"} ]";
NSData* data=[str dataUsingEncoding:NSUTF8StringEncoding];
NSArray* jsonArr=[NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

NSLog(@"%@",jsonArr);