【问题标题】:How to show Json data in TableviewCell?如何在 TableviewCell 中显示 Json 数据?
【发布时间】:2016-11-07 05:29:38
【问题描述】:

我从 Webservice 获取这些数据

dict : {
    "Apparel & Accessories" = 2;
    "Automotive Services" = 0;
    "Building and Construction" = 1;
    "Business & Professional Services" = 0;
    "Business Services" = 0;
    "Community & Education" = 0;
    Education = 0;
    "Entertainment & Media" = 2;
    FREIGHT = 0;
    "Family & Community" = 0;
    Finance = 0;
    "Finance & Legal" = 1;
    "Food & Dining" = 3;
    "Health & Medicine" = 2;
    "Home & Garden" = 0;
    "Home Repair & Improvement" = 0;
    "Industrial supplies & services" = 0;
    "Information Technology" = 1;
    Legal = 0;
    PELLETS = 0;
    "Personal Care" = 2;
    "Public utilities & environment" = 0;
    "Real Estate" = 0;
    "Real Estate & Insurance" = 0;
    Shopping = 0;
    "Shopping & Specialty Stores" = 0;
    "Sports & Recreation" = 0;
    "TRANSPORT SERVICES" = 0;
    Transportation = 0;
    Travel = 1;
    "Travel & Lodging" = 0;
    Uncategorized = 0;
}

我必须根据下面给出的图像在表格视图中显示这些数据

请告诉我该怎么做,我不知道该怎么做... 谢谢

【问题讨论】:

  • 我不是要代码,只是想知道如何在键前获取这些值...@FawadMasud,我已经在 tableview 中获得了所有键
  • 我建议你买一本关于编程的书。
  • 解析 json 这是很有帮助的教程。 raywenderlich.com/5492/working-with-json-in-ios-5

标签: ios objective-c json uitableview


【解决方案1】:

我可以告诉你如何做到这一点 - 只需在数组中添加所需的键。例如:Education,freight 然后你可以在表格视图中显示数组中的数据。

【讨论】:

  • 好的,我明白了,我已经这样做了 NSArray *valuesArray = [dictTemp allValues];NSArray *keysArray = [dictTemp allKeys]; ,并在表格视图单元格中显示这些键和值
  • 正确。您只需要显示数组中的这些值。
【解决方案2】:
NSString *key = [[dict allKeys] objectAtIndex:indexPath.row]
cell.textLabel.text = [NSString stringWithFormat:@"%@ (%@)",key,[dict objectForKey:key]];

;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-28
    • 2020-11-29
    • 2018-12-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多