I tried to make a put request to server with JSON type and it gives me error. Here is error detail.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (_SwiftValue)'
Here is a code.
var attdList : JSON = [:]
...
var clientsAry = attdList["clients"]
...
let params = ["clients" : clientsAry, "submitted" : 1]
...
Alamofire.request(url + req_task, method: .put, parameters: params, encoding: JSONEncoding(options: []), headers:headers).responseJSON { response in
...
I printed params variable and it displays like this. Could anyone please help this?
▿ 1 element
▿ 0 : 2 elements
- key : "clients"
▿ value : [
{
"id" : null,
"hours" : "0",
"client" : {
"id" : 2,
"name" : "Anders Andersson"
}
},
{
"id" : null,
"hours" : "1",
"client" : {
"id" : 4,
"name" : "Gun Gunsson"
}
},
{
"id" : null,
"hours" : "2",
"client" : {
"id" : 3,
"name" : "Johan Johansson"
}
},
{
"id" : null,
"hours" : "3",
"client" : {
"id" : 1,
"name" : "Maria Martinsson"
}
}
]
▿ rawArray : 4 elements
▿ 0 : 3 elements
▿ 0 : 2 elements
- key : "id"
- value : <null>
▿ 1 : 2 elements
- key : "hours"
- value : "0"
▿ 2 : 2 elements
- key : "client"
▿ value : 2 elements
▿ 0 : 2 elements
- key : "id"
- value : 2
▿ 1 : 2 elements
- key : "name"
- value : Anders Andersson
▿ 1 : 3 elements
▿ 0 : 2 elements
- key : "id"
- value : <null>
▿ 1 : 2 elements
- key : "hours"
- value : "1"
▿ 2 : 2 elements
- key : "client"
▿ value : 2 elements
▿ 0 : 2 elements
- key : "id"
- value : 4
▿ 1 : 2 elements
- key : "name"
- value : Gun Gunsson
▿ 2 : 3 elements
▿ 0 : 2 elements
- key : "id"
- value : <null>
▿ 1 : 2 elements
- key : "hours"
- value : "2"
▿ 2 : 2 elements
- key : "client"
▿ value : 2 elements
▿ 0 : 2 elements
- key : "id"
- value : 3
▿ 1 : 2 elements
- key : "name"
- value : Johan Johansson
▿ 3 : 3 elements
▿ 0 : 2 elements
- key : "id"
- value : <null>
▿ 1 : 2 elements
- key : "hours"
- value : "3"
▿ 2 : 2 elements
- key : "client"
▿ value : 2 elements
▿ 0 : 2 elements
- key : "id"
- value : 1
▿ 1 : 2 elements
- key : "name"
- value : Maria Martinsson
- rawDictionary : 0 elements
- rawString : ""
- rawNumber : 0
- rawNull : <null>
- rawBool : false
- type : SwiftyJSON.Type.array
- error : nil