我有字典,我想用来填写tableview。它由JSON解析。
我的字典看起来像这样:
NSLog(@"%@",temp);
// OUTPUT //
(
{
ShootingDate = "2013-07-29 00:00:00";
ShootingID = 1;
ShootingName = Testshooting;
},
{
ShootingDate = "2013-06-12 00:00:00";
ShootingID = 2;
ShootingName = Architektur;
}
)
Dictionary在XCode中看起来像那样:
现在我想用这些数据填充表格。每行应显示ShootingDate,ShootingID和ShootingName,但我无法访问这些键。
有人提出建议吗?
答案 0 :(得分:0)
首先,temp不是字典,它是NSArray,你可以把它作为
for (NSDictionary *dictionary in temp) {
[dictionary valueForKey:@"ShootingDate"];
[dictionary valueForKey:@"ShootingID"];
[dictionary valueForKey:@"ShootingName"];
}
您可以在cellforRow中获取字典
NSDictionary *tempDicts=[temp objectAtIndex:indexPath.row];
cell.textLabel.text=[NSString stringWithFormat:@"id=%@,date=%@,name=%@",[tempDicts valueForKey:@"ShootingID"],[tempDicts valueForKey:@"ShootingDate"],[tempDicts valueForKey:@"ShootingName"]];
答案 1 :(得分:-1)
您可以
访问这些密钥 NSString *str_ShootingDate = [[temp objectAtIndex:indexpath.row]
objectForKey:@"ShootingDate"]; //you can change this key with ShootingID
//or ShootingName