2017-05-27 15 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は私のjson文字列を 'let poststring = "Json_strong"の中に設定する方法を教えてくれますか? –

+0

あなたはデータまたはオブジェクトのjson Stringを持っていますか? –

+0

オブジェクトparth brother –