Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用RestKit映射JSON数组_Ios_Json_Restkit - Fatal编程技术网

Ios 如何使用RestKit映射JSON数组

Ios 如何使用RestKit映射JSON数组,ios,json,restkit,Ios,Json,Restkit,我有如下格式的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: Co

我有如下格式的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?

使用

[[RKObjectManager sharedManager].mappingProvider addObjectMapping:myObject];
您应该检查Restkit对象映射文档的“”部分

以下是文档中的一个示例:

[
    { "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];

对我来说,解决办法是:

添加此响应描述符,使用de数组中的对象

[manager addResponseDescriptor:[ObjectInsideTheArray getResponseDescriptor]];
在成功的回应中


NSArray*响应=(NSArray*)[mappingResult数组]//不是firstObject,而是JSON字典的正确格式,我认为在顶层添加一个键是正式的。我猜这不是你用来编辑的json,很有趣。我还没找到一个办法。幸运的是,我还控制了我的服务器,并修改了服务器以添加顶级key.hmm,looks list当前RK版本没有这个
-addObjectMapping
方法。我们现在能做什么?有更新吗?这个答案有5年了。。。现在不在iOS上开发:C