2016-01-21 62 views
1

这里面是响应:RestKit如何映射一个数组的数组

{ 
    "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 
    } 
    ] 
} 

我要地图并获得唯一所有的“文档”里的数组键入“结果”,我也不需要什么其他对象/映射。我只需要这些文件。如何在响应描述符中完成/声明,以便将所有这些文档自动匹配到我的托管对象?

+0

那你试试?什么没有用? – Wain

回答

0

试试这个: -

NSDictionary *[email protected]{ 
        @"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的需要!

+0

这个答案与restkit无关 – Wain

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"]); 
} 

你可以试试这个.. :)

+0

这个答案与restkit无关 – Wain