Convert String(already formatted) to an Array of NSDictionary

81 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 best solutions below

0
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);