[英]Mantle parsing array
I am using mantle framework
to parse JSON
file. 我正在使用披风framework
来解析JSON
文件。 My JSON
object Looks like this 我的JSON
对象看起来像这样
[{
key:value
key:value
},
{
key:value
key:value
} ]
My object is array
that doesn't have key. 我的对象是没有键的array
。 How could we parse this array
? 我们如何解析这个array
? How should the JSONKeyPathsByPropertyKey
method be implemented? JSONKeyPathsByPropertyKey
方法应如何实现?
As mentiond on the Library description 如图书馆说明中所述
This method Specifies how to map property keys to different key paths in
JSON
此方法指定如何将属性键映射到JSON
不同键路径
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{
@"items" : @"",
};
So how could we map array
property to JSON
object that doesn't have a key ? 那么如何将array
属性映射到没有键的JSON
对象呢?
I assume, You are getting an array in response of an API call and you want to parse it. 我假设,您正在获得一个数组以响应API调用,并且您想解析它。
So as per your JSON. 因此,按照您的JSON。 You need to create a MTLModel subclass for the type of objects in the array. 您需要为数组中的对象类型创建一个MTLModel子类。
Then you can parse the array and create the models of the object types in array. 然后,您可以解析数组并在数组中创建对象类型的模型。 Like this: 像这样:
NSArray *objects = [MTLJSONAdapter modelsOfClass:[model class] fromJSONArray:[PASS THE ARRAY] error:nil];
Hope that helps. 希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.