Objective-C
iPhone

ネストしたJSONデータのプロパティアクセスにはvalueForKeyPath:が便利

More than 5 years have passed since last update.

[jsonDict valueForKeyPath:@"piyo.poyo"];などで直感敵にアクセスできる

NSString *json = @"{ \"hoge\" : \"fuga\", \"piyo\" : { \"poyo\" : \"fuga\" } }";
NSError *error;
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:[json dataUsingEncoding:NSUTF8StringEncoding] options:0 error:&error];
NSString *value = [jsonDict valueForKeyPath:@"piyo.poyo"];
NSLog(@"val: %@", value); // val: fuga