【问题标题】:Map JSON to array of my model - ObjectMapper将 JSON 映射到我的模型数组 - ObjectMapper
【发布时间】:2016-10-17 19:13:19
【问题描述】:

我在使用 ObjectMapper 将 json 映射到我的对象数组时遇到了麻烦。这是我的模型对象。

class Participant : Mappable {

var user_global_id: String!
var user_app_id: String!

init(){
}

required init?(_ map: Map) {
}

// Mappable
func mapping(map: Map) {
    user_global_id    <- map["user_global_id"]
    user_app_id    <- map["user_app_id"]
}
}

我的 json 看起来:"[{\"user_global_id\":5093363330056192,\"user_app_id\":11}]"

我正在调用 ObjectMapper:

let participants = Mapper<[Participant]>().map(json["registeredParticipants"])

上面的行给出错误:Type '[Participant]' does not conform to protocol 'Mappable'

【问题讨论】:

    标签: json swift objectmapper


    【解决方案1】:

    主要的错误是将数组作为通用属性传递。这是解决方案

     Mapper<Participant>().mapArray(json["registeredParticipants"])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-25
      • 1970-01-01
      • 2015-10-25
      • 2017-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多