-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兄弟 –