Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift3 Alamofire Post请求问题_Swift3_Alamofire_Xcode8 - Fatal编程技术网

Swift3 Alamofire Post请求问题

Swift3 Alamofire Post请求问题,swift3,alamofire,xcode8,Swift3,Alamofire,Xcode8,为什么以下代码会给出错误: Alamofire失败:-错误域=Alamofire.AFError代码=4“JSON无法序列化,原因是错误: 无法读取数据,因为它的格式不正确。“服务器的响应不是JSON。也许你得到了一个错误的回应。我建议您检查响应错误代码或使用curl尝试相同的请求 let parameters = [ "checkout": [ "email": "john.smith@example.com", "line

为什么以下代码会给出错误:

Alamofire失败:-错误域=Alamofire.AFError代码=4“JSON无法序列化,原因是错误:
无法读取数据,因为它的格式不正确。“

服务器的响应不是JSON。也许你得到了一个错误的回应。我建议您检查响应错误代码或使用curl尝试相同的请求

   let parameters = [
        "checkout": [
            "email": "john.smith@example.com",
            "line_items": [
                "variant_id": 31342168513,
                "quantity": 1
                ],
            "shipping_address": [
                "first_name": "John",
                "last_name": "Smith",
                "address1": "126 York St.",
                "city": "Ottawa",
                "province_code": "ON",
                "country_code": "CA",
                "phone": "(123)456-7890",
                "zip": "K1N 5T5"
            ]
        ]
    ]

    let urlString = "https://\(Key):\(Password)@sapphireonline-staging.myshopify.com/admin/checkouts.json"
    let headers: HTTPHeaders = [
        "X-Shopify-Storefront-Access-Token": "5681ded39ead3fa6f4594ad0981367",
        "Content-Type": "application/json"
    ]

    Alamofire.request(urlString, method:.post, parameters: parameters,encoding: JSONEncoding.default, headers:headers).responseJSON { response in
        switch response.result {
        case .success:

            print("\n\n Alamofire Response . resposne :- ", response)
        case .failure(let error):

            print("\n\n Alamofire Failure :- ",error as NSError)
        }
    }