我尝试使用 Alamofire 发出这样的 API 请求:
let param = ["id":"xy", "products":[["quantity":2, "product":["id":123]]]]
Alamofire.request(url, method: .post,
parameters: param, encoding: URLEncoding.default,
headers: ["Accept": "application/json", "Content-Type": "application/json"]).responseJSON ..
我收到了这样的回复:
message = "Unexpected token i in JSON at position 0";
statusCode = 400;
我也尝试提出这样的请求:
request.httpBody = try! JSONSerialization.data(withJSONObject: param)
我尝试手动执行以下请求以确保它工作正常:
curl -X POST http://url -d'{"id":"xy", "products" [{"quantity":2,"product":{"id":123}}]}' -H'Content-Type: application/json'
根据需要,它给了我这样的回应:
{
"id":"xy",
"products":[
{
"quantity":2,
"product":{
"id":123
}
}
]
}