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...

TimD
  • 8,014
  • 2
  • 24
  • 34
  • What do you get if you print them in your code (printf or NSLog) and not via gdb – mmmmmm Mar 18 '10 at 16:09
  • 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... – TimD Mar 18 '10 at 21:09

2 Answers2

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.

Wevah
  • 28,182
  • 7
  • 83
  • 72
  • 3
    Furthermore, the `-description` method's output should **not** be used for anything but debugging purposes. – bbum Mar 18 '10 at 18:27
  • @bbum 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: – Alexander Jul 20 '14 at 22:56
  • @Wevah : 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.. – iShwar Aug 09 '16 at 10:00
  • You shouldn't be using -description for passing to an API. – Wevah Aug 10 '16 at 01:47
1

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

Avinash
  • 4,304
  • 1
  • 23
  • 18