ios - 如何在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", "2", "3", "4"], "product_id": ["100", "200", "300", "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", message: (response.error?.localizedDescription)!, vc: nil)
completion(nil,response.error)
print("Error \(String(describing: response.result.error))")
}
}
}
解决方案
推荐阅读
- javascript - 几行 javasript 来格式化货币
- javascript - 为什么 String.prototype.match() 返回 null 而不是空数组?
- javascript - 如何将图像的原始大小设置为不超过父容器的宽度
- uwp - UWP WebView 中的 Xterm.js - 以编程方式粘贴
- html - 给定布局的引导网格(或 IE 兼容的 CSS 网格)
- java - 如何使用 Trie 进行部分自动完成
- c# - 需要帮助将多个复选框列表中的数据插入数据库
- openlayers - 未触发 OpenLayer 翻译事件
- mysql - mysql 在 cast() 时按大小写
- javascript - HTML 文件未从 javascript 文件中提取信息