0
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSLog(@"Succeeded! Received %d bytes of data",[_configData length]);

    NSString *responseJSONString = [[NSString alloc] initWithData:_configData encoding: NSASCIIStringEncoding];
    NSLog(@"Response: %@", responseJSONString);

    // convert to dictionary 'settingsDictionary'
    NSError* error = [[NSError alloc] init];
NSDictionary *settingsDictionary = [NSJSONSerialization JSONObjectWithData:_configData options:kNilOptions error:&error];
NSLog(@"Dictionary of JSON objects ::: \n%@", settingsDictionary);   // why?!

    NSLog(@"DONE");

yeilds this in Output terminal:

 2013-05-22 11:38:59.318 Tests[8817:c07] didReceiveResponse:
 responseData length:(0) 2013-05-22 11:38:59.320 Tests[8817:c07]
 Succeeded! Received 114 bytes of data 2013-05-22 11:38:59.321
 Tests[8817:c07] Response: {"CustomerName":"Example Company","HostName":"streaming1.mycompany.com\/live","AppName":"streamer","Port":"1935"}
 2013-05-22 11:38:59.321 Tests[8817:c07] Dictionary of JSON objects :::
 {
     AppName = streamer;
     CustomerName = "Example Company";
     HostName = "streaming1.mycompany.com/live";
     Port = 1935; 
 } 
 2013-05-22 11:38:59.322 Tests[8817:c07] DONE

I don't understand why, if all the json values are enclosed in quotations, only 2/4 dictionary items include them. What is NSDictionary supposed to store by default?

user
  • 3,388
  • 7
  • 33
  • 67
  • 1
    That's the way that NSDictionary `description` formats the data. Quotes are only used when the data is not a single contiguous "word", without any blanks or special characters. It has nothing to do with the way the data is actually stored inside the dictionary. – Hot Licks May 22 '13 at 16:08

2 Answers2

2

Only those values are quoted in the description which aren't proper identifiers (i. e. there are spaces, special characters, and not just alphanumeric characters). The description of the dictionary doesn't print the keys and values as-is. (Specifically, they aren't actually quoted).

This has nothing to do with them being quoted in the JSON. In JSON, every string is quoted, always.

  • So pulling these objects from the NSDictionary into strings (or comparing the dictionary items to strings) would work normally and the same for each item? – user May 22 '13 at 16:09
  • 1
    @user nothing else would really make sense... –  May 22 '13 at 16:11
  • 1
    @user please don't take my comment as an attack, but you must try before ask. – Vertig0 May 22 '13 at 16:13
  • 1
    Patricio, I realize. But H2CO3's 5 seconds of thinking saved me 10 minutes of dickering. And for that, I hope my upvote and acceptance of his answer is fair compensation. – user May 22 '13 at 16:24
1

Strings with spaces and special characters like dot are surrounded by " to denote that it is single entity. Normal words and numbers are self explanatory.

Vignesh
  • 10,205
  • 2
  • 35
  • 73