2013-05-06 77 views
-3

我是新來的iphone無法理解如何解析這些數據,所以我會在表格視圖中顯示結果。以下數據是AFHTTPRequestOperation的結果,當我調用megento的api時。如何解析這些數據

{ 
     "callforprice_id" = 13; 
     country = Austria; 
     "created_time" = "2013-05-03 12:03:05"; 
     emailid = "[email protected]"; 
     message = hfhftrfygjh; 
     name = "Richard Conover"; 
     "phone_no" = 8977896; 
     "product_name" = Ottoman; 
     "product_options" = ""; 
     "update_time" = "0000-00-00 00:00:00"; 
    }, 
     { 
     "callforprice_id" = 12; 
     country = "Antigua and Barbuda"; 
     "created_time" = "2013-05-03 12:01:24"; 
     emailid = "[email protected]"; 
     message = sdfsdfsdfwe; 
     name = "Richard Conover"; 
     "phone_no" = 5645; 
     "product_name" = Ottoman; 
     "product_options" = ""; 
     "update_time" = "0000-00-00 00:00:00"; 
    }, 
     { 
     "callforprice_id" = 11; 
     country = Angola; 
     "created_time" = "2013-05-03 11:58:51"; 
     emailid = "[email protected]"; 
     message = 6tyrtyryrty; 
     name = "Kaitlyn Matheson"; 
     "phone_no" = 564564; 
     "product_name" = Ottoman; 
     "product_options" = ""; 
     "update_time" = "0000-00-00 00:00:00"; 
    } 
+0

它的答案取決於你想要如何顯示數據。在細胞中表示你想要展示的物品? – 2013-05-06 06:22:41

回答

1
  1. 在一個NSArray * jsonDataArray完全拿這個。
  2. 在TableView numberOfRowsInSection中使用return [jsonDataArray Count];
  3. 在tableview SelectRowAtIndexPath中需要一個NSDictionary * dictionary =(NSDictionary *)[jsonDataArray objectAtIndex:indexPath.row];在這本詞典中,你會分別得到每個對象
  4. 然後你可以通過[dictionary objectForKey:@「attribute_name」]訪問任何元素;
+1

如何在tablview中僅顯示姓名和電子郵件ID – 2013-05-06 06:50:13

+1

NSString * email = [NSString stringWithFormat:@「%@」,[dictionary objectForKey:@「emailid」]]; – 2013-05-06 06:59:24

+0

它是從我的字典中收集所有電子郵件ID還是隻收集一個。以及如何我可以給表視圖爲例如myTableview.textLabel.text = – UnderGround 2013-05-06 07:07:20

1

嘗試這樣的,如果你想在UITableview顯示的數據,然後使用這一個,用於獲取數據,如字典

for(NSDictionary *dict in resultArray){ 
     NSString *str=[dict valueForKey:@"country"]; 

    }