2016-11-07 158 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]]; 

;