我成功使用RESTKit來訪問Web服務。但我有問題將服務器錯誤(如404,403 ...)映射到RESTKit的標準RKErrorMessage類。比方說,我從我的服務提出了以下JSON響應一個403個狀態碼在一起:使用RESTKit映射服務器錯誤
{"errors":{"message":"Some error message"}}
在我的iOS應用程序,我嘗試錯誤的幫助下圖:
RKObjectMapping *errorMapping = [RKObjectMapping mappingForClass:[RKErrorMessage class
[errorMapping addPropertyMapping:[RKAttributeMapping
attributeMappingFromKeyPath:@"message" toKeyPath:@"message"]];
statusCodes4xx = RKStatusCodeIndexSetForClass(RKStatusCodeClassClientError);
errorDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:notecardMapping
pathPattern:nil keyPath:@"errors" statusCodes:statusCodes4xx];
但所有我get是從RESTkit發出的錯誤:
Failed mapping operation: No mappable values found for any of the attributes or relationship mappings
我的錯在哪裏?例如,它在描述符中只是一個錯誤的路徑?
我認爲你想'@「errors.message」'作爲你的密鑰 – mkral
也不應該是'addAttributeMapping'? – mkral
謝謝你的回答。不幸的是,「errors.message」也不起作用。我的代碼與RESTKit網站上描述的解決方案非常相似:[link](https://github.com/RestKit/RestKit)。但是他們不會爲他們的例子發佈相應的服務器響應。 – Benni