-1
我需要將以下json傳遞給此函數,以便Shopify Api可以理解提交。我無法建立正確的變量格式,並把它傳遞給server.Shopify API期待下面的JSON通過POST將json參數發送到api使用post方法Swift 3
我需要將以下json傳遞給此函數,以便Shopify Api可以理解提交。我無法建立正確的變量格式,並把它傳遞給server.Shopify API期待下面的JSON通過POST將json參數發送到api使用post方法Swift 3
傳遞您的API URL
更換REQUEST_URL替換爲JSON_STRING您實際的JSON字符串
var request = URLRequest(url: URL(string: "REQUEST_URL")!)
request.httpMethod = "POST"
let postString = "JSON_STRING"
request.httpBody = postString.data(using: .utf8)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data, error == nil else { // check for fundamental networking error
print("error=\(error)")
return
}
if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 { // check for http errors
print("statusCode should be 200, but is \(httpStatus.statusCode)")
print("response = \(response)")
}
let responseString = String(data: data, encoding: .utf8)
print("responseString = \(responseString)")
}
task.resume()
轉換你的對象爲字典,然後通過
序列化
parth你能告訴我如何在'let poststring ='Json_strong'中設置我的json字符串嗎? –
你有json你的數據或對象的字符串嗎? –
對象parth兄弟 –