2016-11-17 65 views
-2
var parameters = [String:Any]() 
parameters = ["user_type_id":"1" ,"user_name":userName.text ,"user_password":password.text,"user_fname":firstName.text,"user_lname":lastName.text,"user_phone":"0000000","city_id":"1", "land_size": "10","location_ID":"2", "image_ID":"1","email":"aaaaa"] as [String : Any] 



Alamofire.request(url ,method : HTTPMethod.post , parameters: parameters , encoding: JSONEncoding.default).responseJSON {(response: DataResponse<Any>)in print(response.result.value) 
      print("success") 

我使用alamofire發送登記數據到網絡服務器,它給我的錯誤:無效類型的JSON寫(_SwiftValue)」錯誤:無效類型JSON寫

+0

是四個'.text'值自選項目? – vadian

回答

0

只是做這樣的

parameters = ["user_type_id":"1" ,"user_name":"\(userName.text)" ,"user_password":"\(password.text)","user_fname":"\(firstName.text)","user_lname":"\(lastName.text)","user_phone":"0000000","city_id":"1", "land_size": "10","location_ID":"2", "image_ID":"1","email":"aaaaa"] as [String : Any] 
0

你做了錯誤,而價值分配到這些下面的鍵user_nameuser_passwordfirstName.textlastName.text,這是不正確的格式。

嘗試這樣,

var parameters = [String:Any]() 
parameters = ["user_type_id":"1" ,"user_name": "\(userName.text)" ,"user_password": "\(password.text)","user_fname":"\(firstName.text)","user_lname":"\(lastName.text)","user_phone":"0000000","city_id":"1", "land_size": "10","location_ID":"2", "image_ID":"1","email":"aaaaa"] as [String : Any] 

Alamofire.request(url ,method : HTTPMethod.post , parameters: parameters , encoding: JSONEncoding.default).responseJSON {(response: DataResponse<Any>)in print(response.result.value) 
print("success") 

謝謝:)

相關問題