[英]Create a dictionary in swift with alamofire
我試圖在 swift 中使用 alamofire 創建一個 web 請求,請求對象應該是這樣的
{
"warranty": 0,
"descriptions": "string",
"product_name": "string",
"purchase_date": "23/10/2016",
"product_image": "string",
"product_receipt": "string",
"serial_number": "string",
"barcode_image": "string",
"serial_number_image": "string",
"product": {
"id": 1
},
"user": {
"id": 12
}
}
所以為了得到這個,我把我的代碼作為這個
let parameters :[String:AnyObject] = [
"warranty":product.warrenty,
"descriptions":product.longDescription,
"product_name":product.initialName,
"purchase_date":product.purchaseDate,
"serial_number":product.serialCode,
"product": [
"id":product.id
],
"user": [
"id":userDefaults.getCustomerId()
]
]
但是當我提出請求時,服務器似乎不接受這種格式,可能是我分配的方式
"product": {
"id": 1
},
"user": {
"id": 12
}
不正確,這里有什么問題? 有人能指出我在這里做的問題嗎
我遇到了同樣的問題,問題是,我缺少您需要設置 .JSON 的編碼選項。 將下面的行與您的相匹配。
Alamofire.request(.POST, strURL, parameters: parameter as? [String : AnyObject], encoding: .JSON).responseJSON { (response: Response<AnyObject, NSError>) in
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.