Reputation: 695
Here's the response:
{
"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
}
]
}
I want to map and get only all the "document" inside an array keyed "result" and I don't need anything with other objects / mappings. I just need the documents. How can that be done / declared in the response descriptors to automatically match all these documents to my managed object?
Upvotes: 1
Views: 50
Reputation: 657
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"]);
}
You may try this.. :)
Upvotes: 0
Reputation: 105
Try This :-
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
}
]
};
I am storing your response in NSDictionary and get it by -
[[[dic objectForKey:@"result"] objectAtIndex:0] objectForKey:@"documents"]
change your indexNumber as require !
Upvotes: 0