LoginSignup
62
62

More than 5 years have passed since last update.

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

Last updated at Posted at 2012-03-21

[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
62
62
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
62
62