如何解析JSON响应并在Objective C中使用它?

时间:2017-01-12 06:17:40

标签: ios objective-c json

我正在开发一款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"];
    }

1 个答案:

答案 0 :(得分:0)

for(NSDictionary*projectvalue in response) 
{
    for(NSDictionary *projectvalue1 in projectvalue) 
    {
        _projectName = [projectValue1 valueForKey:@"time"]; _active = [projectValue1 valueForKey:@"is_active"]; 
    } 
}