NSMutableDictionary is adding quotes to keys and values - why?
Asked Answered
B

2

5

I'm trying to add some additional key/value pairs to an NSMutableDictionary, using:

Tag *tag1 = [results1 objectAtIndex:0];
[resultsDict setObject:[tag1 retrieveTextUpToDepth:1] forKey:@"image_url"];

Tag *tag2 = [results2 objectAtIndex:0]; 
[resultsDict setValue:[tag2 retrieveTextUpToDepth:1] forKey:@"majority"];

This adds the k/v pairs with no problem, except when I come to retrieve them, some of the values have been wrapped with double quotes:

po extendedDataDictionary:

    "image_url" = "/images/mpsL/11727.jpeg";
    majority = 3460;

Both keys and values are NSStrings, with no quotes - so I'm stumped as to where they're appearing from.

Is there any way of preventing this?

Or am I going to have to live with it and try to strip off the quotes once I've retrieved the value?

Thanks...

Benfield answered 18/3, 2010 at 16:7 Comment(2)
What do you get if you print them in your code (printf or NSLog) and not via gdbConceivable
It's the same via NSLog: 2010-03-18 21:08:24.312 Conflict[49224:40b] extendedDataDictionary = { "image_url" = "/images/mpsL/13735.jpeg"; majority = 2484; swing = "4.6"; "vulnerability_cohort" = 643; "vulnerability_rank" = 488; All the values come from the same XML feed, and there's definitely no quotes in the image_url field...Benfield
S
11

The quotes aren't really part of the content; the -description method (called by po, IIRC) simply wraps things in quotes for display that have non-alphanumeric characters in them.

Shammer answered 18/3, 2010 at 16:30 Comment(4)
Furthermore, the -description method's output should not be used for anything but debugging purposes.Simmon
@Simmon learned this the hard way. For hours I was convinced that NSDictionaries couldn't print unicode characters... It ended up being that description removes them D:Soissons
@Shammer : Its fine values with special characters got wrapped in double quotes but what if the say password field must have one special character then the API call is failing because of this unwanted double quotes. How one should prevent -description method from wrapping that double quotes to particular fields..Mineralogist
You shouldn't be using -description for passing to an API.Shammer
L
1

Adding to it, you can use keys or values neglecting the quotation and it should be fine..

Latreshia answered 2/10, 2013 at 4:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.