0
解析5個陣列中的一個對象,我被困在這個問題中,JSON的輸出是如何使用JSON
"forecast":[
{"day":"Today","condition":"MostlyClear","high_temperature":"94","low_temperature":"70"},
{"day":"Tomorrow","condition":"Sunny","high_temperature":"95","low_temperature":"69"},
{"day":"Saturday","condition":"Sunny","high_temperature":"94","low_temperature":"71"},
{"day":"Sunday","condition":"Sunny","high_temperature":"93","low_temperature":"70"},
{"day":"Monday","condition":"Sunny","high_temperature":"94","low_temperature":"70"}
]
我需要狀態鍵顯示在tableview中單元格的值。而我的代碼是
temp=[[NSString alloc] initWithData:[dataLoader httpData] encoding:NSUTF8StringEncoding];
NSLog(@"Patient Details %@",temp);
array = [[temp JSONValue] objectForKey:@"forecast"];
NSDictionary* dic = [array objectAtIndex:[indexPath row]];
NSString *strDay = [dic objectForKey:@"day"];
NSString *stringCondition = [dic objectForKey:@"condition"];
NSLog(@"condition is %@", stringCondition);
NSString *stringTemp = [dic objectForKey:@"high_temperature"];
NSString *stringLow = [dic objectForKey:@"low_temperature"];
但是它顯示只有一個條件值,我想所有這一切的時候5個條件。我也嘗試使用NSArray
而不是NSString
,因爲沒有運氣。
是否只顯示1行?正如你使用「indexPath行」,我假設這在一些UITableViewController的cellForRowAtIndexPath中運行。如果是這樣,你返回第0部分的行數是什麼? –