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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With