Nsstring to Nsdictionary conversion always null

Asked

Viewed 35 times

0

I am converting Nsstring to Nsdictionary but when I step inside a variable always returns null.

what I am doing:

NSDictionary *json =
[NSJSONSerialization JSONObjectWithData: [body dataUsingEncoding:NSUTF8StringEncoding]
                                options: NSJSONReadingMutableContainers
                                  error: nil];

Where body is my variable, but if I put her content there everything works normal!

What could be going on?

conteúdo da variável: @"{\"teste\" : \"ehtetra\"}"

1 answer

1


Try this:

NSString *suaString = @"{\"teste\" : \"ehtetra\"}";

NSData *data = [suaString dataUsingEncoding:NSUTF8StringEncoding];
id novoJson = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

NSLog(@"JsonOutput:%@",novoJson);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.