2017-05-27 104 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兄弟 –

相關問題