无法使用ObjectMapper Swift 4.1进行序列化

时间:2018-05-21 23:29:31

标签: ios swift realm

尝试使用Alamofire和AlamofireObjectMapper时出现错误

我调用api的功能

static func getUberIntegration(completion: @escaping ([Integrations]?) -> ()) {
        let url = "\(Url.baseURL())/integrations"
        let headers = Headers.authorization()

        Alamofire.request(url, headers: headers).responseArray { (response: DataResponse<[Integrations]>)  in

          let integration = response.result.value
            print(integration!)

            completion(integration)

        }
    }

模型

class Integrations: Object, Mappable {

   @objc dynamic var id: Int32 = 0
   @objc dynamic var type: String = ""
   @objc dynamic var active: Bool = false

    override static func primaryKey() -> String? {
        return "id"
    }

    required convenience init?(map: Map) {
        self.init()
    }

    func mapping(map: Map) {
        id <- map["id"]
        type <- map["type"]
        active <- map["active"]

    }


}

状态代码200

时来自API的响应
    {
    "id": 120,
    "type": "Integration",
    "active": true
    }

任何人都可以解释为什么会出现这个问题?当我打印调试状态代码是返回代码200但无法读取json数据

我收到此错误

  

错误Domain = com.alamofireobjectmapper.error Code = 2“ObjectMapper   无法序列化回复。“

0 个答案:

没有答案