我正在使用休息套件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和标题。
我打电话给他们开始请求
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"
}
注意:请求和响应中的值是虚拟值,但它们的结构是给定的
答案 0 :(得分:2)
<RKMappingResult: 0x849bf60, results={ "<null>" = "<Response: 0x849b390>";
这看起来像是一个有效的回复。响应映射为您提供了一个字典,其中键是键路径,响应是您指定的对象。因此,在这种情况下,密钥为nil
,您的对象为Response
。并且Response
没有实施description
方法,因此您只需获取地址。
您还没有显示您的映射或描述符,因此我无法说出更多信息。您可以在调试器中查看Response
的内容......