Question

How can i parse below data:

 u = "{\"userid\":\"Living123\"}";

I need to get Living123 as a string.

Was it helpful?

Solution

You can use this library to convert NSString to NSDictionary. Import "SBJson.h" in your .m file and use following code

NSDictionary *dictionary = [u JSONValue];
NSString *userId = [dictionary valueForKey:@"userid"];

Edit

Alternatively you can use NSJSONSerialization to convert NSString to NSDictionary

NSError *e = nil;
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:u options:NSJSONReadingMutableContainers error:&e];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top