6

So I am currently sending back from my server a JSON object. If I do a print of the responseObject in XCode, I get the following:

Printing description of responseObject:
{
order = 3;
"picture_bucket_name" = test;
"picture_creation_date" = "2013-01-06T21:49:54.546Z";
"picture_identifier" = 61;
"picture_url_with_bucket" = "test/pictures/sop/steps/test_default_320_320.png";
"sub_order" = 0;
 }

Why is the Order key not in " "? This is the only key with a Number that I have to convert from NSString to NSNumber using a NumberFormatter. Why is that?

Carl Veazey
  • 18,392
  • 8
  • 66
  • 81
abisson
  • 4,365
  • 9
  • 46
  • 68
  • I suppose it's just a peculiarity in Xcode. It's the only key without an underscore in your example. Maybe they omit it for readability. Idiomatic JSON should quote every key. – Chris Jan 06 '13 at 22:04

1 Answers1

7

Normally a single word without any spaces and other special characters are shown without any quotes in console for the dictionary key. For eg:- the key order and the value test in above example. That is helpful for maintaining the readability. Wrapping these other words in quotes ensure the readability.

iDev
  • 23,310
  • 7
  • 60
  • 85
  • I see. Now, why do I have to do newStep.order = [f numberFromString:[responseObject valueForKey:@"order"]]; for my order, and I can simply do newStep.subOrder = [responseObject valueForKey:@"sub_order"]; , even though BOTH of them are required to be NSNumber in my "newStep" object? – abisson Jan 07 '13 at 01:01
  • In objective c `order` represents a variable name and `"order"` represents a string literal. Both are not the same when you are using in your code. The above applies only for displaying in console. I am not sure what is this `newStep.order` you mentioned here. The first one should be an NSNumber object and second one should be string or so. – iDev Jan 07 '13 at 01:39
  • Sorry for the lack of coherence. If you look at the pasted Output, I am trying to use the [responseObject valueForKey:@"order"] as a NSNumber, but Xcode tells me it is a String and I need to convert it using the Formatter. But, as you can see, there are no " ". Why does it tell me it is a string?! – abisson Jan 07 '13 at 02:17
  • @abisson, That is weird. Are you printing the above using an NSLOG statement? Check with that. It should be an NSNumber if it is just `3` and not `"3"`. That is what I have seen. – iDev Jan 07 '13 at 05:22