Conversion from NSString to NSDictionary always null

0

I'm converting NSString to NSDictionary however when I step inside a variable it always returns null.

What I'm doing:

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

Where body is my variable, but if I put the contents of it there everything works normal!

What could be happening?

conteúdo da variável: @"{\"teste\" : \"ehtetra\"}"
    
asked by anonymous 30.10.2014 / 13:21

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);
    
30.10.2014 / 13:34