与 Alamofire 混合 JSON

Mixed JSON with Alamofire

我正在尝试使用 Alamofire 发出 POST HTTP 请求以将设备数据上传到 Swift 中的 The Things Network;但是,我收到一条错误消息,告诉我“协议类型 'Any' 的值不能符合 'Encodable';只有 struct/enum/class 类型可以符合协议”。我该如何解决这个问题以便我可以使用这个字典?

    let params: [String : Any] = [
        "altitude": 0,
        "app-id": "some-app-id",
        "attributes" : [
            "key": "",
            "value": ""
        ],
        "description": "some description of the device",
        "dev_id": "some-dev-id",
        "latitude": 52.375,
        "longitude": 4.887,
        "lorawan_device": [
            "activation_constraints": "local",
            "app_eui": "0102030405060708",
            "app_id": "some-app-id",
            "app_key": "01020304050607080102030405060708",
            "app_s_key": "01020304050607080102030405060708",
            "dev_addr": "01020304",
            "dev_eui": "0102030405060708",
            "dev_id": "some-dev-id",
            "disable_f_cnt_check": false,
            "f_cnt_down": 0,
            "f_cnt_up": 0,
            "last_seen": 0,
            "nwk_s_key": "01020304050607080102030405060708",
            "uses32_bit_f_cnt": true
        ]
    ]

AF.request("{url}", method: .post, parameters: params, encoder: JSONParameterEncoder.prettyPrinted).response { response in
        print(response)

因为[String: Any]没有确认Encodable

替换

AF.request("{url}", method: .post, parameters: params, encoder: JSONParameterEncoder.prettyPrinted).response { response in
        print(response)
}

AF.request("{url}", method: .post, parameters: params, encoding: JSONEncoding.prettyPrinted).response { response in
        print(response)
}