-2

我有字典,我想用它来填充表格视图。它由 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;
    }
)

字典在 XCode 中看起来像这样:

在此处输入图像描述

现在我想用这些数据填充一个表。每行应显示 ShootingDate、ShootingID 和 ShootingName 但我无法访问这些键。

有人建议吗?

4

2 回答 2

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"]];
于 2013-07-29T13:37:50.520 回答
-1

您可以访问这些密钥

    NSString *str_ShootingDate = [[temp objectAtIndex:indexpath.row] 
    objectForKey:@"ShootingDate"];  //you can change this key with ShootingID 
    //or ShootingName
于 2013-07-29T13:36:19.767 回答