gpt4 book ai didi

ios - RestKit RKObjectMapping.. 嵌套和一次性对象

转载 作者:行者123 更新时间:2023-11-29 01:55:48 24 4
gpt4 key购买 nike

所以,我有一个 api 调用,它将以下面的格式输出一些原始 json...

有点乱,但我只对此 json 的 Mapping 部分感兴趣。如果我能够访问原始数据,我会将 json 序列化为我想要迭代的字典/数组。但是客户端正在使用 Restkit,这似乎并不像我想象的那么容易。 ...

另外我应该如何处理图像部分?同样,如果使用序列化的 json 执行此操作,我可以打开字典并使用 name description 等设置对象内部的内容...我也可以这样做吗?

{
"rsp": {

sn : "SerialNumber",
name : "Service Name",
from : "2000-01-01T00:00:00.000+01:00",
to : "2000-01-02T00:00:00.000+01:00",
mappings : {

"mapping" : {

"1" : {

from : 2000-06-01T00:01:00.000+01:00
to : 2000-06-01T01:02:00.000+01:00
content : {

name : "name"
description : "description"
images : {
image : "b47ab5a8.png"
}
}
},
"2" : {

from : 2000-06-01T00:01:00.000+01:00
to : 2000-06-01T01:02:00.000+01:00
content : {

name : "name"
description : "description"
images : {
image : "b47ab5a8.png"
}
}
},

// etc...

我的问题是

 // what goes here

RKObjectMapping *itemMapping = [RKObjectMapping mappingForClass:[MYItem class]];

[itemMapping addAttributeMappingsFromDictionary:@{@"description":@"itemDescription",
@"name":@"name"}];

如何将图像添加到MYItem

最佳答案

对于图像,您的映射类似于:

[itemMapping addAttributeMappingsFromDictionary:@{@"description":@"itemDescription",
@"name":@"name",
@"images.image":@"image"}];

即关键路径有效但是,并不是说它们只适用于字典。您不能以相同的方式任意索引数组。

关键路径也在响应描述符中,这就是您深入到 mapping 的方式,即 rsp.mappings.mapping(同样,因为它是字典)。

关于ios - RestKit RKObjectMapping.. 嵌套和一次性对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30873211/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com