ios - 将字符串与数组一起传递,但使用 Alamofire 在 swift 中将字符串读取为 null

标签 ios arrays swift string alamofire

我使用 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/

相关文章:

iphone - 如何在应用内购买中恢复购买?

ios - UITableViewCell + 动态高度 + 自动布局

C 列表插入程序 - 运行时出现段错误

c++ - 使用数组查找 HCF,得到未知输出 (C++)

ios - 由于 'private' 级保护 - swift,无法访问“restoreProgress”

ios - 此服务器的证书无效。您可能正在连接到伪装成 “domain” 的服务器

iphone - 给 CAShapeLayer 添加阴影,让里面保持透明

iOS:支持用户数量的最佳实践

php - 帮助解码 JSON

当 UITextField.secureTextEntry 改变它的值时 Swift 得到回调