error when passing JSON parameter

0

When I pass the parameter that a JSON expects, I get the error that "can not convert value type String to expected argument type JSON" (aka 'Optional Dictionary (String, Any')

this is the data

  var params: JSON = ["token": token, "system": "system", "dev": dev]

  if let jsonData = try? JSONSerialization.data(withJSONObject: params, option: .prettyPrinted) {
  if let jsonString = String.init(data: jsonData, encoding: .ascii) {

and in this function to send the data is where I missed the error in jsonString, in the wait function a JSON object comes as well within the function

  APICLient..... params: JSON? = nil...

and I put it in such a way so that I get it as JSON

  APICLlient.request(nil, method: .pos, path: .postupdate, params: jsonString) { (response, succees) in 

 // mas codigo ->
}
}
}

I convert it because it does not execute or send nil in the function since it waits for a JSON but I miss that error ...

    
asked by Yan Cervantes 21.03.2018 в 17:36
source

1 answer

1

You do not need to transform your var params: JSON... into data, or later to a jsonString ... You already have it as JSON type, which is the type that waits for what your error says, then that is what you need to pass to your function.

var params: JSON = ["token": token, "system": "system", "dev": dev]
APICLlient.request(nil, method: .pos, path: .postupdate, params: params) { (response, succees) in 

     // mas codigo ->
}
    
answered by 23.03.2018 / 18:47
source