如何将JSON响应的多维数组映射到Alamofire+;对象映射器?
我正试图用Alamofire+ObjectMapper开始我的项目 我可以用对象数组(带键)进行简单的映射 但是,这是一个必须的情况,我必须处理以下类型的JSON格式,它有一些问题: 1:非常嵌套的数组(三维) 2:每层阵法都没有钥匙 所以我不能创建JSON表示的对象。请帮忙如何将JSON响应的多维数组映射到Alamofire+;对象映射器?,json,swift,multidimensional-array,alamofire,objectmapper,Json,Swift,Multidimensional Array,Alamofire,Objectmapper,我正试图用Alamofire+ObjectMapper开始我的项目 我可以用对象数组(带键)进行简单的映射 但是,这是一个必须的情况,我必须处理以下类型的JSON格式,它有一些问题: 1:非常嵌套的数组(三维) 2:每层阵法都没有钥匙 所以我不能创建JSON表示的对象。请帮忙 我的JSON字典: 我的模型: 我得到的是: 如果JSON的结构是数组数组,则可以使用: 让responseArrayOfArrays=Mapper().mapArrayOfArrays(JSONObject:respo
我的JSON字典: 我的模型: 我得到的是:
如果JSON的结构是数组数组,则可以使用:
让responseArrayOfArrays=Mapper().mapArrayOfArrays(JSONObject:response?.rawValue)也许这会给你一些想法:一个建议是不要使用AlamoFileObjectMapper(你似乎在使用它),但只要你得到
responseJSON
@Hexfire的响应,就尝试手动预解析你的JSON谢谢你的回复!!我在github上检查了这个问题,但是没有帮助,因为JSON的结构不同,我仍然不知道如何处理我的JSON。@Hexfire对于你的第二个建议,你能给我一些示例代码或如何处理的参考吗?如果您能为我提供一个完整的JSON代码,我将不胜感激!!
{
"structure_model": [
[
[
{
"test": "test"
}
]
]
]
}
class Component: Mappable, Codable {
var test : String = ""
required init?(map: Map) {
}
func mapping(map: Map) {
test <- map["test"]
}
}
class StructureModel: Mappable, Codable {
var structureModels : [Array<Array<Component>>]?
required init?(map: Map){
}
func mapping(map: Map) {
structureModels <- map["structure_model"]
}
}
Alamofire.request(API, method: .post, parameters: parameters, encoding: JSONEncoding.default).validate().responseObject { (response: DataResponse<StructureModel>) in etc... }
structureModels = [
[
[Component, Component, ...],
[Component, Component, ...],
...
] ,
[
[Component, Component, ...],
[Component, Component, ...],
...
] ,
...]
structureModels = nil