如何解析 JSON 响应并在 Objective C 中使用它?
Posted
技术标签:
【中文标题】如何解析 JSON 响应并在 Objective C 中使用它?【英文标题】:How to Parse JSON Response and utilize it in Objective C? 【发布时间】:2017-01-12 06:17:39 【问题描述】:我正在开发一个 ios 应用程序。我收到 JSON 响应,我该如何解析它?它由两个不同的按钮数据组成。我如何计算它并显示在按钮详细信息上?
JSON 响应:
0 =
date = "0000-00-00";
"is_active" = 1;
project = "New project";
"project_desc" = "New project";
"project_id" = 3;
time = "<null>";
"user_id" = 6;
;
1 =
date = "2017-01-04";
"is_active" = 1;
project = "New Project 2";
"project_desc" = "New Project 2";
"project_id" = 4;
time = "06:29:54";
"user_id" = 6;
;
status = 1;
解析代码:
- (void)serverDidReceiveResponse:(NSDictionary *)response
NSLog(@"%@",response);
for (NSDictionary *projectValue in response)
_projectName = [projectValue valueForKey:@"time"];
_active = [projectValue valueForKey:@"is_active"];
【问题讨论】:
_projectName = [[projectValue valueForKey:@"time"]objectAtIndex:0]; [for(NSDictionary*projectvalue in response)
for(NSDictionary *projectvalue1 in projectvalue)
_projectName = [projectValue1 valueForKey:@"time"]; _active = [projectValue1 valueForKey:@"is_active"];
【讨论】:
以上是关于如何解析 JSON 响应并在 Objective C 中使用它?的主要内容,如果未能解决你的问题,请参考以下文章