我使用 Alamofire 在 API 命中时将字符串和数组一起传递给一个参数。
但是响应时间我的字符串读为空,请任何人向我建议。
这些是我的参数
let apiurl = "https://www.furnitureinfashion.net/FIF-APP/app_array_cart.php?"
let params:[String:Any] = ["customer_id":"152698",
"product_id":["27372","31872"],
"qty":["3","4"],
"option":["1202",""]]
找到我的API点击代码如下
Alamofire.request(apiurl, method:.get, parameters: params, encoding: JSONEncoding.default).responseJSON { (response) in
if response.result.value != nil{
print(response)
}else{
print(response.result.error?.localizedDescription ?? "")
}
}
我收到这样的回复:
SUCCESS: {
Message = "Customer id missing";
cusid = "<null>";
status = "Not ok";
}
最佳答案
这是仅基于后端人员所需的正确方法,这意味着我们发送解码或编码的格式
这是后端问题。
Alamofire.request(apiurl, method:.get, parameters: params, encoding: JSONEncoding.default).responseJSON { (response) in
if response.result.value != nil{
print(response)
}else{
print(response.result.error?.localizedDescription ?? "")
}
}
关于ios - 将字符串与数组一起传递,但使用 Alamofire 在 swift 中将字符串读取为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59066514/