0
我想,包括我的快捷應用程序內Zoho的圖書API ZOHO的書籍POST方法。 我想創建一個項目使用POST方法,但我不斷有一個錯誤消息說我的JSONString是錯誤的。中使用JSON的斯威夫特3
這裏是ZOHO文檔發送請求,使用POST方法,以創造和項目:
https://books.zoho.com/api/v3/items
?authtoken=e07119171812c29b3a0dacdb79a57e3f
&organization_id=10234695
&JSONString={
"name": "Hard Drive",
"description": "500GB, USB 2.0 interface 1400 rpm, protective hard case.",
"rate": 120.00,
"account_id": "460000000000388",
"tax_id": "460000000027005"
}
這是我做。我感到莫名其妙我JSONString犯規達到預期格式...
let postData = [
"authtoken" : "ZZZZZZZZZZZZZZZZZZZZZZ",
"organization_id" : "XXXXXXXXXXX",
"JSONString" :
[
"name": "Hard Drive",
"description": "500GB, USB 2.0 interface 1400 rpm, protective hard case.",
"rate": 120.00,
"account_id": "460000000000388",
"tax_id": "460000000027005"
]
] as [String : Any]
var request = URLRequest(url: NSURL(string:"https://books.zoho.eu/api/v3/items")! as URL)
request.httpMethod = "POST"
request.httpBody = try! JSONSerialization.data(withJSONObject: postData, options: [])
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
Alamofire.request(request).responseJSON
{ response in
if let JSON = response.result.value {
let zohoResponse: [String: AnyObject] = JSON as! [String : AnyObject]
print(zohoResponse)
}
}
而答案:
["code": 4, "message": Invalid value passed for JSONString]
我管好,使GET請求,所以我認爲它應該是管理使用中的POST方法我的快速應用程序也是如此。
非常感謝您的幫助
問候