我收到响应错误..知道吗?与Alamo fire一起使用swift,我必须将发布请求发送为http正文行

时间:2018-11-18 10:26:31

标签: ios swift xcode

let parameters = ["order": ["line_items": [
    ["variant_id": 18055889387589, "quantity": 11]]]] as [String : Any]


Alamofire.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.prettyPrinted, headers: headers).responseJSON { response in
    switch response.result {
    case .success:
        print("response is ",response)
    case .failure(let error):
        print(0,"Error")
    }
}

1 个答案:

答案 0 :(得分:-2)

let parameters = ["order": ["line_items": [
    ["variant_id": 18055889387589, "quantity": 11]]]] as [String : Any]

let jsonData = try! JSONSerialization.data(withJSONObject: parameters)
let jsonString = NSString(data: jsonData, encoding: String.Encoding.utf8.rawValue)

我认为问题在于您的参数请尝试这个