如何在Swift中使用api公共管理器类删除传递数组的json解析错误作为参数?

我正在尝试将商品数组作为参数传递,但是我收到错误,请任何人纠正。

这些是我的参数和网址:

https://www.furnitureinfashion.net/FIF-APP/app_array_cart.php
let proids = ["100","200","300","400"]
let quantity = ["1","2","3","4"]
    let params:[String:Any] = ["product_id":proids,"qty":quantity]

我收到以下错误:

https://www.furnitureinfashion.net/FIF-APP/app_array_cart.php
["qty": ["1","4"],"product_id": ["100","400"]]
JSON could not be serialized because of error:
The data couldn’t be read because it isn’t in the correct format.
Error Optional(Alamofire.AFError.responseSerializationFailed(reason: Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(error: Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.})))
2019-11-26 15:59:53.612426+0530 Furniture in Fashion[13014:196121] Warning: Attempt to present <UIAlertController: 0x7f97d314e800>  on <Furniture_in_Fashion.WishListVC: 0x7f97d2ebaa20> which is already presenting (null)

请使用以下内容找到我的API管理器类。

 func apiDataarrayPostMethod(url:String,parameters:[String:Any],completion: @escaping (_ data:[String:Any]?,_ error:Error?) -> Void)
    {
        UIApplication.shared.isnetworkactivityIndicatorVisible = true
        let manager = Alamofire.Sessionmanager.default
        manager.session.configuration.timeoutIntervalForRequest = 45

        manager.request(url,method:.post,parameters: parameters,encoding: JSONEncoding.default,headers: headersintoApi()).responseJSON { (response:DataResponse<Any>) in

            UIApplication.shared.isnetworkactivityIndicatorVisible = false 
            if response.result.isSuccess
            {
                print("Response Data: \(response)")

                if let data = response.result.value as? [String:Any]
                {
                    completion(data,nil)

                }else{
                    Helper.Alertmessage(title: "Alert",message: (response.error?.localizedDescription)!,vc: nil)

                    completion(nil,response.error)
                }
            }
            else
            {
                Helper.Alertmessage(title: "Alert",vc: nil)
                completion(nil,response.error)
                print("Error \(String(describing: response.result.error))")
            }

        }
    }
jinkaixin1980 回答:如何在Swift中使用api公共管理器类删除传递数组的json解析错误作为参数?

您的数据不是有效的JSON。使用this网站,您可以对其进行验证。它应该是: {"qty": ["1","2","3","4"],"product_id": ["100","200","300","400"]}

它应该以{{1​​}}和{开头和结尾,而不是}[。另请参见here

,

请尝试使用responseString而不是responseJSON。解释以下答案。

https://stackoverflow.com/a/33541493/9673374

本文链接:https://www.f2er.com/3029954.html

大家都在问