1

我正在使用休息套件 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"
}

注意:请求和响应中的值是虚拟值,但它们的结构是给定的

4

1 回答 1

2

<RKMappingResult: 0x849bf60, results={ "<null>" = "<Response: 0x849b390>";

这看起来像是一个有效的回应。响应映射为您提供了一个字典,其中键是键路径,响应是您指定的对象。所以,在这种情况下,关键是nil,你的对象是Response. 并且Response没有实现该description方法,因此您只需获取地址。

你还没有显示你的映射或描述符,所以我不能说更多。您也许可以查看Response调试器中的内容...

于 2013-09-27T15:15:11.127 回答