0

Tastypie API にアクセスするために RestKit を使用しています。私は両方の端を制御しています。

次のように、「/api/v1/organizations/1/」で「裸の」JSON リソースを正常にロードするように RestKit マッピングを構成しました。

{
"id": "1", 
"name": "ACME Space"
}

/api/v1/organizations/しかし、次のようなリソースをロードするように RestKit を構成するにはどうすればよいですか。

{
"meta": 
    {
        "limit": 20, 
        "next": null, 
        "offset": 0, 
        "previous": null, 
        "total_count": 2
    }, 
"objects": 
    [
        {
            "id": "1", 
            "name": "ACME Space"
        },
        {
            "id": "2", 
            "name": "XYZ Tech"
        }
    ]
}

RestKit はmetaキーまたはオブジェクトobjectsに使用されているキーが気に入らないと思いOrganizationます。

でこれをやろうとしていRKFetchedResultsTableControllerます。オーバーライドできるデリゲート コールバックや、RestKit が気に入らない余分な JSON を取り除くためにサブクラス化できるクラスはありますか? Tastypie が JSON 応答を発行する方法を変更する方が簡単でしょうか?

この質問は、この unanswered SO questionに似ています。

4

2 に答える 2

2

I would recommend that you take a look at the feature/reboot-networking-layer branch that is currently in the late stages of development. One of the many features in there is a harmonization of key-path and URL based mapping configurations using a new class called RKResponseDescriptor. Basically this lets you say, when I load an object at this path pattern (in this case, /api/v1/organizations) map the 'objects' key path using the given mapping. This works around previous problems with key path ambiguity for generic key paths like 'objects'.

There is extensive documentation in the headers (published at http://restkit.org/api/0.20.0-dev/index.html) and a new README.md published to https://github.com/RestKit/RestKit/tree/feature/reboot-networking-layer.

于 2012-09-26T22:50:02.190 に答える
0

TastyPie の開発バージョンには、Meta.collection_name区別するために使用できる属性があります。こちらのドキュメントを参照してください。

それが整ったら、Metaクラスを作成してマップしforKeyPath:@"meta"、RestKit が残りを把握しました。1 つのメタ オブジェクトと N 個の実際のオブジェクトを含むオブジェクト リストを取得します。

于 2012-11-06T09:39:34.113 に答える