2013-05-06 31 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"]; 

    }