2015-11-13 502 views
1

我使用Alamofire發出了一些HTTP請求。有些請求已成功,有些請求失敗。Alamofire HTTP請求失敗

誤差爲Invalid value around character 0.

請求失敗給了我上面的錯誤。

波紋管我提到了一個失敗的示例代碼。

let parameters = ["amount": ["10"], "payment_method": ["paypal"], "date": ["2015-11-25"], "details": ["Payment description"]] 

    let headers = [ 
     "Accept": "*/*", 
     "Content-Type": "application/json" 
    ] 

    let url = "https://livetest.somedomain.com/api/invs/LAT1j5da99PdPg/payments?auth_token=pbtTEPNki3hUhGBuPX3d" 

    Alamofire.request(.POST, url, parameters: parameters, encoding: .JSON, headers: headers) 
     .responseJSON { response in 
      let results = response.result 
      print(results) 
      print(response.debugDescription) 
    } 

請幫我找到問題

回答

0

這個問題已經發生,因爲JSON傳遞的格式不正確的。然後我改變了參數如下

let parameters = ["payment":["amount": "100" , "payment_method": "check", "date": "2015-11-25", "details": "Payment description dimuth Lasantha"]] 

現在它傳遞正確的格式,它是

{ 
payment: { 
    "amount" : "100", 
    "payment_method" : "check", 
    ..... 
    } 
}