如何提取数据值并添加到tableview

时间:2014-10-23 18:55:19

标签: objective-c json uitableview nsmutablearray nsdictionary

如何从以下数据结构中提取数据,并在tableview上显示

id = extractData
[extractData objectForKey:@"data"] //BELOW IS OUTPUT:

 ( {
       Name =  {
            id = 2;
            name = rat;
        };
        Place =  {
            id = 7;
            name = New York;
        };
        Item =   {
            Times = "100";
            “expire” = 10-19-2015;
            “value” = 300;
            id = 1;
            name = newname;
            “checked” = 0;
        };
        Type =  {
            id = 1;
            name = round;
        };
    },
        {
        Name =  {
            id = 2;
            name = norway;
        };
        Place =   {
            id = 3;
            name = ops;
        };
        Item =  {
            Times = "100";
            “expire” = 10-18-2015;
            “value” = 300;
            id = 1;
            name = new;
            “checked” = 1;
        };
        Type =         {
            id = 2;
            name = square;
        };
    }
)

希望在每次迭代时在tableview单元格中显示名称,地点,项目,类型值。 可以任何一个建议,如何从上面的数据中提取价值。

1 个答案:

答案 0 :(得分:0)

在初始化自定义单元格后,在您的cellForRowAtIndexPath下添加以下代码:

NSDictionary *dicVal = [yourDataArray objectAtIndex:indexPath.row];

cell.labelName.text = [[dicVal objectForKey:@"Name"] objectForKey:@"name"];
cell.labelPlace.text = [[dicVal objectForKey:@"Place"] objectForKey:@"name"];
cell.labelItem.text = [[dicVal objectForKey:@"Item"] objectForKey:@"name"];
cell.labelType.text = [[dicVal objectForKey:@"Type"] objectForKey:@"name"];

return yourCustomCell;

这应该做的工作。感谢。