- (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");
在输出终端中产生这个:
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
我不明白为什么,如果所有的 json 值都用引号括起来,那么只有 2/4 的字典项包含它们。NSDictionary 默认应该存储什么?