1

这是回应:

{
  "status": true,
  "statuscode": 200,
  "result": [
    {
      "name": "ABC",
      "date": "2015-01-30",
      "documents": [
        {
          "id": 1,
          "name": "doc1",
          "status": "complete",
        },
        {
          "id": 2,
          "name": "doc2",
          "status": "complete",
        },
        {
          "id": 3,
          "name": "doc3",
          "status": "complete",
        }
      ],
      "message": "Hello World",
      "status": 3
    }
  ]
}

我想映射并仅获取数组键控“结果”中的所有“文档”,并且我不需要其他对象/映射的任何内容。我只需要文件。如何在响应描述符中完成/声明以自动将所有这些文档与我的托管对象匹配?

4

2 回答 2

0

尝试这个 :-

NSDictionary *dic=@{
                    @"status": @true,
                    @"statuscode":@ 200,
                    @"result": @[
                            @{
                                @"name": @"ABC",
                                @"date": @"2015-01-30",
                                @"documents": @[
                                        @{
                                            @"id":@ 1,
                                            @"name": @"doc1",
                                            @"status": @"complete",
                                            },
                                        @{
                                            @"id":@ 2,
                                            @"name": @"doc2",
                                            @"status":@ "complete",
                                            },
                                        @{
                                            @"id":@ 3,
                                            @"name": @"doc3",
                                            @"status": @"complete",
                                            }
                                        ],
                                @"message": @"Hello World",
                                @"status":@ 3
                                }
                            ]
                    };

我将您的回复存储在 NSDictionary 中并通过 -

 [[[dic objectForKey:@"result"] objectAtIndex:0] objectForKey:@"documents"]

根据需要更改您的 indexNumber !

于 2016-01-21T05:45:44.293 回答
0
NSDictionary *jsonData = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];  //From Server you will get response data in form of NSData , so the 'responseData' is a type of NSData
NSArray *appDetais = [jsonData objectForKey:@"result"];
NSDictionary *resultJsonData = [appDetais objectAtIndex:0];
NSArray *documentDetailsArray = [jsonData resultJsonData:@"documents"];
for(int i=0;i<[documentDetailsArray count];i++){
   NSDictionary *singleDocumentDetail = [documentDetailsArray objectAtIndex:0];
   NSLog(@"%@",[singleDocumentDetail objectForKey:@"id"]);
}

你可以试试这个.. :)

于 2016-01-21T05:49:11.457 回答