2017-05-27 103 views

回答

0

传递您的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() 

转换你的对象为字典,然后通过

序列化
+0

parth你能告诉我如何在'let poststring ='Json_strong'中设置我的json字符串吗? –

+0

你有json你的数据或对象的字符串吗? –

+0

对象parth兄弟 –

相关问题