Search code examples
iosiphonejsonpushwoosh

How can i parse json data from pushwoosh iphone


How can i parse below data:

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

I need to get Living123 as a string.


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];