私のバックエンドは、この種の JSON ファイルを返します。
{ "応答": { "メッセージ": "テスト" }, "応答コード": 205 }
responseCode の値によって、response の内容が異なります。RKDynamicMapping のようなものを使用する必要があることはわかっていますが、その方法がわかりません。私が見る問題は、サンプル コードとマニュアルでは、マッピングを区別するための属性が内側になっているのに、この場合は外側になっていることです。私はこれを試しましたが、うまくいきません:
[dynamicMapping setObjectMappingForRepresentationBlock:^RKObjectMapping *(id representation) {
NSNumber* responseCode=(NSNumber*)representation[@"responseCode"];
if (responseCode.integerValue==204) {
return searchByLocatorResponseContent204Mapping;
} else if (responseCode.integerValue==205) {
return searchByLocatorResponseContent205Mapping;
}
return nil;
}];
RKResponseDescriptor *searchByLocatorResponseContentResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:dynamicMapping pathPattern:kCheckinSearchByLocatorPath keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[objectManager addResponseDescriptor:searchByLocatorResponseContentResponseDescriptor];
私が変更したいマッピングには、それらを区別するための属性が含まれていないためだと思います(残りのキットのWebサイトから女の子/男の子のサンプルコードを入力するなど)
誰かお勧めはありますか?前もって感謝します。