问题
I made some HTTP requests using Alamofire. Some request has been succeeded and some are failed.
error is Invalid value around character 0.
Failed request gave me above error.
bellow i have mentioned a sample code which failed.
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)
}
Please help me to find the issue
回答1:
This issue was happened because of wrong format of JSON passing. Then i changed the parameter as follows
let parameters = ["payment":["amount": "100" , "payment_method": "check", "date": "2015-11-25", "details": "Payment description dimuth Lasantha"]]
Now it passes the correct format which is
{
payment: {
"amount" : "100",
"payment_method" : "check",
.....
}
}
来源:https://stackoverflow.com/questions/33699900/alamofire-http-requests-fails