5

私はこの形式のようなjson文字列を持っています:

[{"image":"/0001.jpg","link":"/index.php"},
{"image":"/0001.jpg","link":"/index.php"}]

最上位にキーはありません。

[mapping mapKeyPath:@"image" toAttribute:@"image"];

このようなマッピングは機能しません。エラーが発生します。

restkit.object_mapping:RKObjectMapper.m:81 Adding mapping error: Could not find an object mapping for keyPath: ''

このタイプの json をマップする方法は?

4

2 に答える 2

1

使用する

[[RKObjectManager sharedManager].mappingProvider addObjectMapping:myObject];

Restkit Object Mapping Docs の「 Mapping without KVC 」セクションを確認する必要があります。

ドキュメントの例を次に示します。

[
    { "title": "RestKit Object Mapping Intro",
      "body": "This article details how to use RestKit object mapping...",
      "author": {
          "name": "Blake Watters",
          "email": "blake@restkit.org"
      },
      "publication_date": "7/4/2011"
    }
]

そして、次のようにマッピングします。

// Our familiar articlesMapping from earlier
RKObjectMapping* articleMapping = [RKObjectMapping mappingForClass:[Article class]];
[articleMapping mapKeyPath:@"title" toAttribute:@"title"];
[articleMapping mapKeyPath:@"body" toAttribute:@"body"];
[articleMapping mapKeyPath:@"author" toAttribute:@"author"];
[articleMapping mapKeyPath:@"publication_date" toAttribute:@"publicationDate"];

[[RKObjectManager sharedManager].mappingProvider addObjectMapping:articleMapping];
于 2012-06-10T20:55:11.887 に答える
0

私にとっての解決策は次のとおりです。

この応答記述子を追加し、配列内のオブジェクトを使用します

[manager addResponseDescriptor:[ObjectInsideTheArray getResponseDescriptor]];

そして成功応答で

NSArray *response = (NSArray *)[mappingResult配列]; //firstObject の代わりに

于 2015-01-30T10:49:18.440 に答える