0
我已經做了一個API調用添加產品到購物車。而在按鍵的動作我這樣做API calling.I需要發送一些特定的參數,當我使用郵遞員代碼。其在我的代碼引發許多錯誤API。但是:後迅速發送的API調用參數
func addtocartapicalling()
{
let headers = [
"cache-control": "no-cache",
"postman-token": "4c933910-0da0-b199-257b-28fb0b5a89ec"
]
let postData = NSData(data: "{
"cartType" : "1",
"cartDetails" : {
"customerID" : "u",
"cartAmount" : "6999",
"cartShipping" : "1",
"cartTax1" : "69",
"cartTax2" : "",
"cartTax3" : "",
"cartCouponCode" : "",
"cartCouponAmount" : "",
"cartPaymentMethod" : "",
"cartProductItems" : {
"productID" : "9",
"productPrice" : "6999",
"productQuantity" : "1"
}
}
}".dataUsingEncoding(NSUTF8StringEncoding)!)
var request = NSMutableURLRequest(URL: NSURL(string: "http://api.php")!,
cachePolicy: .UseProtocolCachePolicy,
timeoutInterval: 10.0)
request.HTTPMethod = "POST"
request.allHTTPHeaderFields = headers
request.HTTPBody = postData
let session = NSURLSession.sharedSession()
let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
println(error)
} else {
let httpResponse = response as? NSHTTPURLResponse
println(httpResponse)
}
})
dataTask.resume()
}
見我上面的代碼,是否有任何API調用,請幫助我。
感謝
let string = "{\"cartType" : "1" + "cartDetails" : { "customerID" : "u", + "cartAmount" : "6999", + "cartShipping" : "1", + "cartTax1" : "69", + "cartTax2" : "", + "cartTax3" : "", + "cartCouponCode" : "", + "cartCouponAmount" : "", + "cartPaymentMethod" : "",} + "cartProductItems" : { "productID" : "9", + "productPrice" : "6999", + "productQuantity" : "1" }" }"
我試着寫修復像你的解決方案。但仍然在該行的一些錯誤。就像要求我添加逗號,就像那 – mack
這不足以幫助我的信息。你需要用你的新代碼更新你的答案。 – Frankie
請檢查我的updat – mack