Reputation: 473
Objective C:
RKObjectMapping *responseMapping = [RKObjectMapping mappingForClass:[Response class]];
[responseMapping addAttributeMappingsFromArray:@[@"status",@"description"]];
[manager addResponseDescriptorsFromArray:@[
[RKResponseDescriptor responseMapping
pathPattern:nil
keyPath:@"Details"
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]
]];
JSON:
{
"Details" : {
"status":"2012",
"description":"Not valid"
},
"Address":{
...
}
}
The above is the response that i am getting .It has "Details" as well as "Address".
Details mapping is shown in the code above.Address mapping is done in same manner but currently not that important.
in mapping results i get both the objects, ie details as well as address .
I want the json string for DetailMapping from operation. In RKObjectRequestOperation *operation i am able to get the complete json string that includes details as well as address but i want json string related only to details mapping.
Upvotes: 2
Views: 1651
Reputation: 473
Objective C:
RKManagedObjectRequestOperation *operation = [manager
appropriateObjectRequestOperationWithObject:reqObj
method:RKRequestMethodPOST
path:loginServiceURL parameters:nil];
[operation setWillMapDeserializedResponseBlock:^id(id deserializedResponseBody)
{
NSDictionary *dictionary = [[NSMutableDictionary alloc] init];
dictionary = deserializedResponseBody;
NSString *Details = [dictionary objectForKey:@"Details"];
return deserializedResponseBody;
}];
Upvotes: 2
Reputation: 119031
That isn't what RestKit is designed for so the results it provides are the mapped content and not the source response data.
Which ever way you choose to do it you will likely need to process the whole JSON data to extract the part you want. To get the individual dictionary you would probably need to subclass the mapping operation and inject it into the operation processing your request.
Consider why you want to get access to the JSON. most likely what you want to do can be done in some other way as part of the mapping (perhaps using the mapping metadata).
Upvotes: 1