我正在使用休息套件 0.20.0。我有一个 JSON 格式的请求,就像
{
"CreateSession" : yes,
"DistributionChannel" : "string1",
"Login" : "string2",
"Nickname" :"string3",
"Password" :"string4",
"PhysicalDevice" :
{
"DeviceId" : "string5",
"DeviceTypeCode" : 123,
"PhysicalDeviceTypeCode" : 1233,
}
}
我做了这个
NSDictionary * dictionary = @{
@"CreateSession":@"yes",
@"DistributionChannel":@"string1",
@"Login": @"string2",
@"Nickname": @"string3",
@"Password": @"string4",
@"PhysicalDevice": @{ @"DeviceId": @"string5",
@"DeviceTypeCode": @"123",
@"PhysicalDeviceTypeCode": @"1233" }
};
RKObjectMapping *registerDeviceRequestMapping = [RKObjectMapping requestMapping];
[registerDeviceRequestMapping addAttributeMappingsFromDictionary:dictionary];
分别为请求和响应创建描述符。将其添加到 RKObjectManager 共享对象中,还设置了基本 url 和 headers。
我打电话给这个开始请求
RKHTTPRequestOperation *operation = [[RKObjectManager sharedManager] appropriateObjectRequestOperationWithObject:dictionary method:RKRequestMethodPOST path:@"RegisterDevice" parameters:nil];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"response %@",[responseObject description]);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Failed with error: %@", [error localizedDescription]);
}];
[operation start];
我得到 200 状态,但无法从响应中映射值。我得到的映射结果是
<RKMappingResult: 0x849bf60, results={
"<null>" = "<Response: 0x849b390>";
尝试了几个链接,但似乎没有一个提供好的解决方案。我需要映射的实际响应是
{
"PhysicalDevice": {
"AddDate": "string1",
"AuthenticationKey": "string2",
"DeviceId": "string3",
"DeviceTypeCode": 33,
"DeviceTypeName": "string4",
"Id": 10130,
"ModDate": "2013-09-27T07:21:34.240Z",
"PhysicalDeviceTypeCode": 1233,
"SerialNumber": "string5",
"Status": 1,
"StatusName": "string6"
},
"RemainingDeviceAssociations": 4,
"SessionId": "string7"
}
注意:请求和响应中的值是虚拟值,但它们的结构是给定的