jsonの値を.textで表示させたいのですが、うまくいきません!
表示させたい内容------------------
menu の中にある
"name"の中身 "並盛り"
"price" "300"
"kcal" "680"
#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad{ [super viewDidLoad]; //1つめ json値取得 self.view.backgroundColor = [UIColor whiteColor]; // 読込ローカル // データの取得 NSBundle *bnd01 = [NSBundle mainBundle]; NSString *pth01 = [bnd01 pathForResource:@"test" ofType:@"json"]; NSURL *url01 = [NSURL fileURLWithPath:pth01]; NSURLRequest *req01 = [NSURLRequest requestWithURL:url01]; NSData *dat01 = [NSURLConnection sendSynchronousRequest:req01 returningResponse:nil error:nil]; // JSONオブジェクトの取得 NSDictionary *cor01 =(NSDictionary *) [NSJSONSerialization JSONObjectWithData:dat01 options:NSJSONReadingMutableContainers // 基本的にはこれを選ぶ error:nil]; for (NSDictionary *cor02 in cor01[@"menu"]) { NSLog(@"%@, %@, %@", cor02[@"name"], cor02[@"price"], cor02[@"kcal"]); } _Read_label.text = @"hoge"; _jsonAns = cor01[@"name"]; _Read_label.text = _jsonAns; } // test.json-------------------- //{ // "menu": [ // {"name": "並盛", "price": 300, "kcal": 680}, // {"name": "アタマの大盛", "price": 390, "kcal": 733}, // {"name": "大盛", "price": 460, "kcal": 851}, // {"name": "特盛", "price": 560, "kcal": 1022} // ] //} //------------------------------------------
for文の中のNSLogでは表示されているのでしょうか?
回答1件
あなたの回答
tips
プレビュー