2013-01-16 99 views
0

我使用RestKit框架連接到其他Web服務。 如果我想要resultlistEntries,映射應該如何。 我有這樣的JSON響應:RestKit:JSON映射不起作用Objective-c

{ 
"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. 

請告訴我錯了?

+0

對我沒有提示? – Tomben

回答

0

pathPattern用於指定將使用響應描述符的端點。例如,@"/hotels/premium"作爲pathPattern將意味着如果調用@"/hotels/cheap",則響應描述符將不適用。您可以將其設置爲nil,但我總是希望保持我的回覆描述符儘可能具體。

keypath在JSON響應resultlistEntry陣列在技術上是resultlist.resultlist.resultlistEntries,但你可能與resultlist.resultlist部分的一些問題。我會建議改變你的API來簡單地返回​​然後你需要的鍵路徑將是resultlist.resultlistEntries