【问题标题】:How to extract data values and added to tableview如何提取数据值并添加到tableview
【发布时间】:2014-10-23 18:55:18
【问题描述】:

如何从下面的数据结构中提取数据,并显示在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;
        };
    }
)

想要在每次迭代时在表格视图单元格中显示名称、地点、项目、类型值。 任何人都可以建议,如何从上述数据中提取价值。

【问题讨论】:

  • 在 SO 上有一百个例子,在 Internet 的其他地方还有数百个例子。做一些功课。
  • 一个提示。当您 NSLog 一个 NSArray 时,它会出现包含在 () 中并用逗号分隔的元素。当你 NSLog 一个 NSDictionary 时,它的元素包含在 {} 中并由 ; 分隔,键/值对由 = 分隔。这应该足以让您阅读上述转储并进行处理。
  • @HotLicks 上面是字典数组!!!
  • 你明白了!所以从那里开始。 (请注意,字典包含更多字典。)
  • 感谢您的信息,[[extractData objectForKey:@"data"] count] 给出了计数提取值示例:[[[[extractData objectForKey:@"data"] objectAtIndex:0] objectForKey: @"Place"] objectForKey:@"name"]);

标签: objective-c json uitableview nsmutablearray nsdictionary


【解决方案1】:

在初始化自定义单元格后,在您的 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;

这应该可以完成工作。谢谢。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-25
    • 1970-01-01
    相关资源
    最近更新 更多