Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a JSON String into an NSArray? [closed]

I am facing an issue while converting an NSString to NSArray.

My string is :

["Default", "Discipleship", "Faith", "Family", "Hope", 
 "Life Building", "Love", "Missions", "Relationships"]

What i want to do is get the elements(Default,Discipleship etc.) out of this string and put them into an NSArray.

I have tried a lot but couldn't get it done, please help Any help would be great , thanks in advance

like image 597
Aashish1aug Avatar asked Jul 24 '13 06:07

Aashish1aug


1 Answers

First you convert your string to NSData:

NSString* str = @"[\"Default\",\"Discipleship\",\"Faith\",\"Family\",\"Hope\",\"Life Building\",\"Love\",\"Missions\",\"Relationships\"]";
NSData* data = [str dataUsingEncoding:NSUTF8StringEncoding];

Then, you use:

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

The object array contains the elements of the JSON text.

like image 197
The dude Avatar answered Sep 25 '22 16:09

The dude