Reputation: 1056
I'm trying to use Alamofire to make a POST HTTP request to upload device data to The Things Network in Swift; however, I get an error telling me that "Value of protocol type 'Any' cannot conform to 'Encodable'; only struct/enum/class types can conform to protocols". How would I fix this so I can use this dict?
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)
Upvotes: 0
Views: 273
Reputation: 154
Because [String: Any]
does not confirm Encodable
.
Replace
AF.request("{url}", method: .post, parameters: params, encoder: JSONParameterEncoder.prettyPrinted).response { response in
print(response)
}
to
AF.request("{url}", method: .post, parameters: params, encoding: JSONEncoding.prettyPrinted).response { response in
print(response)
}
Upvotes: 1