将JSON映射到我的模型数组 - ObjectMapper

Sha*_*ili 3 json swift objectmapper

我在使用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"]
}
}
Run Code Online (Sandbox Code Playgroud)

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

我在调用ObjectMapper:

let participants = Mapper<[Participant]>().map(json["registeredParticipants"])
Run Code Online (Sandbox Code Playgroud)

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

Sha*_*ili 6

主要的错误是将数组作为泛型属性传递.这是解决方案

 Mapper<Participant>().mapArray(json["registeredParticipants"])
Run Code Online (Sandbox Code Playgroud)