将 JsonObject 传递给模型 SWIFT

Pass a JsonObject to Model SWIFT

我正在尝试将返回结果列表中的 JSON 对象传递给用户的模型 class。我想在用户对象内部进行所有分配/解析。

我不断收到消息 - 无法使用 JSON

类型的参数调用用户

有什么提示吗?

  let post = JSON(data)

                println("The post is: " + post.description)

                var user : User

                user(post[0])

                println(user.getName())



 import SwiftyJSON

class User {

var ObjectId = ""
  var FirstName = ""
  var LastName = ""
  var Organization = ""
  var CallSign = ""

init(sObjectId : String, sFirstName : String, sLastName : String,     sOrganization : String, sCallSign : String)
  {
ObjectId = sObjectId
FirstName = sFirstName
LastName = sLastName
Organization = sOrganization
CallSign = sCallSign


}

init(sUser : JSON) {

    self.ObjectId = sUser["_id"].string!
    self.FirstName = sUser["firstName"].string!
    self.LastName = sUser["lastName"].string!
    self.Organization = sUser["organization"].string!



}

你必须直接调用适当的初始化程序

let post = JSON(data)
println("The post is: " + post.description)
var user = User(sUser: post[0])