【问题标题】:Pass string along with arrays but string read as a null in swift with Alamofire将字符串与数组一起传递,但使用 Alamofire 在 swift 中将字符串读取为 null
【发布时间】:2020-03-22 19:00:29
【问题描述】:

我使用 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";
}

【问题讨论】:

  • 检查服务器参数 customerId 参数是什么。是cusid 还是customer_id
  • 不不不正确
  • 实际请求是什么?是 POST 请求还是 GET 请求?似乎它将是 POST 请求而不是 GET。
  • 只能从后端获取。

标签: ios arrays swift string alamofire


【解决方案1】:

这是正确的方式,仅基于所需的后端人员意味着我们发送的格式要么是解码的,要么是编码的

这是后端问题。

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 ?? "")
   }
}

【讨论】:

    猜你喜欢
    • 2017-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-26
    • 2016-07-13
    • 2018-10-16
    • 2016-11-20
    相关资源
    最近更新 更多