Вопрос

How can i parse below data:

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

I need to get Living123 as a string.

Это было полезно?

Решение

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];
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top