0

私はこの問題で立ち往生しています、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"}
]

テーブルビューセルに値を表示するには、条件キーが必要です。そして私のコードは

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"];

ただし、条件値は1つしか表示されていません。一度に、5つの条件すべてが必要です。運が悪かったので、条件のNSArray代わりに使ってみました。NSString

4

1 に答える 1

1
 array = [[temp JSONValue] objectForKey:@"forecast"];

この場所で for ループを作成します。

for(NSUInteger index = 0; index<[array count]; index++)
{

 NSDictionary* dic = [array objectAtIndex:index];
 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"];
}

これが役立つことを願っています...

于 2012-09-24T07:27:03.657 に答える