3

私のバックエンドは、この種の 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サイトから女の子/男の子のサンプルコードを入力するなど)

誰かお勧めはありますか?前もって感謝します。

4

1 に答える 1

0

このように設定すると、restkit は、dynamicMapping「応答」の内容だけでなく、応答 json 全体のマッピングを提供することを期待します。

基本的に、フィールドとフィールドsearchByLocatorResponseContent204Mappingのマッピングが必要です。responseresponseCode

representation私の知る限り、パラメーターは現在のコンテキスト内の情報のみを提供するため、restkit は外側を見ることはできません。ただし、それはロードマップ上にあり、これに関するチケットはすでにあります: https://github.com/RestKit/RestKit/issues/1327

于 2013-06-10T22:24:19.123 に答える