2016-11-07 117 views
-4

我从Webservice的如何在TableviewCell中显示Json数据?

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; 
} 

得到这个数据,我必须根据以下

enter image description here

请告诉我该怎么做给定的图像在tableview中显示此数据,我没有想法做到这一点... 谢谢

+0

我不是要求代码只是想知道该怎么做才能在键的前面得到这些值...... @FawadMasud,我已经得到了tableview中的所有键 – user6438311

+0

我建议你买一本关于节目。 – Vincent

+0

解析json这是有帮助的教程。 https://www.raywenderlich.com/5492/working-with-json-in-ios-5 –

回答

1

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

+0

好吧,我明白了,我做了这样的NSArray * valuesArray = [dictTemp allValues]; NSArray * keysArray = [dictTemp allKeys ]。 ,并在tableview单元格中显示这些键和值 – user6438311

+0

正确。你只需要显示数组中的值。 – User511

1
NSString *key = [[dict allKeys] objectAtIndex:indexPath.row] 
cell.textLabel.text = [NSString stringWithFormat:@"%@ (%@)",key,[dict objectForKey:key]]; 

;