Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.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/4/json/14.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 Rest工具包嵌套数组-仅使用一个元素_Ios_Json_Swift_Restkit - Fatal编程技术网

Ios Rest工具包嵌套数组-仅使用一个元素

Ios Rest工具包嵌套数组-仅使用一个元素,ios,json,swift,restkit,Ios,Json,Swift,Restkit,我对Rest工具包有问题,我还没有找到答案。 基本上我有JSON: 和映射: let artistMapping = RKObjectMapping(forClass: Artist.self) artistMapping.addAttributeMappingsFromDictionary(["name": "name", "playcount": "playCount"]) let responseDescriptor = RKResponseDescriptor(m

我对Rest工具包有问题,我还没有找到答案。 基本上我有JSON: 和映射:

    let artistMapping = RKObjectMapping(forClass: Artist.self)
    artistMapping.addAttributeMappingsFromDictionary(["name": "name", "playcount": "playCount"])
    let responseDescriptor = RKResponseDescriptor(mapping: artistMapping, method: RKRequestMethod.GET, pathPattern: "/2.0", keyPath: "topartists.artist", statusCodes: NSIndexSet(index: 200))
我想做的是以小图像url为例,将其映射到我的艺术家类url属性

我在GSON编写自定义反序列化程序时做了类似的事情,但在这里我还没有找到如何做。我不想创建另一个类ImageDescription并在我的Artister类中创建该类的数组。
那么怎么做呢?

你可以作弊一点:

为假设的images数组属性创建一对访问器方法-但不要添加属性,只添加访问器方法。在setter中,处理数组以提取所需的图像并将其存储到true image属性中。数组将包含您需要处理的字典


现在,在您的映射中,将JSON中的images数组键连接到您为其创建访问器方法的假设属性的名称。

它可以工作,可能没有自定义反序列化程序那么干净,但工作得非常好!谢谢。