RestKit:JSON映射不起作用Objective-c

时间:2013-01-16 07:19:52

标签: objective-c web-services restkit

我使用RestKit框架连接到其他Web服务。 如果我想拥有resultlistEntries,映射应该如何。 我有这样的JSON响应:

{
"resultlist.resultlist": {
    "paging": {
        "numberOfHits": 69978,
        "numberOfPages": 3499,
        "pageNumber": 1,
        "pageSize": 20
    },
    "resultlistEntries": [
        {
            "@numberOfHits": "69978",
            "@realEstateType": "7",
            "resultlistEntry": [
                {
                    "@creation": "2013-01-15T16:36:00.000+01:00",
                    "resultlist.realEstate": {
                        "@id": "68014527",
                        "@xsi.type": "search:Office",
                        "calculatedPrice": {
                            "currency": "EUR",
                            "marketingType": "RENT_PER_SQM",
                            "priceIntervalType": "MONTH",
                            "value": 4.5
                        },
                        "commercializationType": "RENT",
                        "courtage": {
                            "hasCourtage": "YES"
                        },
                        "floorplan": "false",
                        "netFloorSpace": 155,
                        "price": {
                            "currency": "EUR",
                            "marketingType": "RENT",
                            "priceIntervalType": "MONTH",
                            "value": 697.5
                        },
                        "totalFloorSpace": 155
                    }
                }
            ]
        }
    ]
}

}

以及以下RestKit代码

NSString *pathPattern = @"resultlist.resultEntries";
NSString *keyPath = @"resultEntry";

RKResponseDescriptor *responseDescriptor = 
    [RKResponseDescriptor responseDescriptorWithMapping:mapping 
                                            pathPattern:pathPattern 
                                                keyPath:keyPath   
                                            statusCodes:statusCodes];

结果如下:

2013-01-15 16:49:00.102 RestKit_final[31840:c07] 
Failed with error: No response descriptors match the response loaded.

什么错了?

1 个答案:

答案 0 :(得分:0)

pathPattern用于指定将使用响应描述符的端点。例如,@"/hotels/premium"作为pathPattern意味着如果您调用@"/hotels/cheap",响应描述符将不适用。您可以将其设置为nil,但我总是希望尽可能保持我的响应描述符。

JSON响应中keypath数组的resultlistEntry在技术上可能是resultlist.resultlist.resultlistEntries,但您可能在resultlist.resultlist部分遇到一些问题。我建议更改您的API,只返回resultList,然后您所需的密钥路径将为resultlist.resultlistEntries