iphone - 如何解析Json对象

标签 iphone objective-c ios xcode json

我被困在 json 对象解析上,真的很努力。问题是如何解析 json 对象。这是我在日志中得到的响应。

{"0":{"**title**":"Test Event","url_title":"test_event1","status":"open","entry_date":"Sep 10, 2012, 

05:20:38AM","entry_id":"26","site_id":"1","channel_id":"3","field_dt_40":null,"field_dt_58":null,"channel_title":"News & 

Events","channel_name":"news_events","start_date":"1348120800","end_date":"1348120800","start_time": "43200","end_time":"46800","where":"FCF","news_event_description":"<p>\n\tLunch with group.<\/p>\n"},

"1":{"**title**":"Test Event 2","url_title":"test_event_2","status":"open","entry_date":"Sep 10, 2012, 05:20:08AM","entry_id":"28","site_id":"1","channel_id":"3","field_dt_40":null,"field_dt_58":null,"channel_title":"News & Events","channel_name":"news_events","start_date":"1348207200","end_date":"1348207200","start_time":"43200","end_time":"46800","where":"FCF - Lunch","news_event_description":"<p>\n\tThis was a great event.<\/p>\n"},

"2":{"**title**":"Test Event 3","url_title":"test_event_3","status":"open","entry_date":"Sep 10, 2012, 05:20:54AM","entry_id":"29","site_id":"1","channel_id":"3","field_dt_40":null,"field_dt_58":null,"channel_title":"News & Events","channel_name":"news_events","start_date":"1346738400","end_date":"1346738400","start_time":"7200","end_time":"11700","where":"FCF - Lunch","news_event_description":"<p>\n\tFall planning season.<\/p>\n"}}

问题是我想在表格 View 中显示所有标题。我可以使用键 0、1、2 获得单个标题。但我希望在解析时立即显示所有标题

请帮帮我,先谢谢了。

最佳答案

假设 jsonDict 是你的 json 字典....试试这个

NSArray * keys=[[NSArray alloc]init];
keys=[jsonDict allKeys];
NSMutableArray *titles=[[NSMutableArray alloc]init];
for(int i=0;i<[keys count];i++){
      [titles addObject:[[jsonDict valueForKey:[keys objectAtIndex:i]]valueForKey:@"title"]];
}
NSLog(@"your array of titles : %@",titles); //use this array to fill your cell

关于iphone - 如何解析Json对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12775695/

相关文章:

iPhone - 使用 2 个 MKMapPoint 定义 MKMapRect

objective-c - 将 Cocoa header 链接到 ruby​​ C 扩展

ios - 具有动态变量的自动布局约束?

ios - swift3 中的数据到 Int/String

ios - 如何将 webview 内容创建为 pdf 文件 ios sdk

iphone - UITableView注册Nib :forCellReuseIdentifier:

iphone - 本地化我的 iphone 应用程序 plist 文件导致错误 "could not read data from ' myAppPath/myApp-Info.plist'

ios - 为什么 NSDateComponents 给我一个不同的日期?

ios - 以编程方式使用自动布局实现带有 subview 的 uiview 子类

objective-c - 使用 NSUserDefaults 存储 NSMutableArray