添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hi im getting this error

Optional(Error Domain=com.alamofire.error Code=-6006 "JSON could not be serialized. Input data was nil or zero length." UserInfo={NSLocalizedFailureReason=JSON could not be serialized. Input data was nil or zero length.})

 let parameters: [String: AnyObject] = [
    "orderNo":orderId,
    "cart": [
            "name": cartItem.name,
            "quantity": cartItem.quantity,
            "amount": cartItem.amount,
            "description": cartItem.description
    "description": description
let headers = ["Content-Type": "application/json"]
Alamofire.request(.POST, UrlManager.someUrl, parameters: parameters, encoding: .JSON, headers: headers).responseJSON { response in
    debugPrint(response)

So this req is not happening, i need in cart send array of unescaped json.
Also found http://stackoverflow.com/questions/37310679/alamofire-json-serialization-error-swift-2-0
Its possible sending array of dict as param?

Regards

Hi @martinkaplan,

The issue I think you're running into is that Alamofire cannot encode your parameters as valid JSON. Most likely something is wrong with your parameters dictionary. I don't see anything obvious in the sample code you posted. I also answered the Stack Overflow question you posted about the NSDate encoding.

What I'd recommend you do is try to encode that parameters object using NSJSONSerialization directory to figure out why the decoding is failing. Once you have that figured out, it should just start working in Alamofire.

In the future, I'd recommend opening a question on Stack Overflow for questions like this. We use our GitHub project for bug reports and feature requests.

Best of luck! 🍻

From our Contribution Guidelines

Asking Questions

We don't use GitHub as a support forum. For any usage questions that are not specific to the project itself, please ask on Stack Overflow instead. By doing so, you'll be more likely to quickly solve your problem, and you'll allow anyone else with the same question to find the answer. This also allows maintainers to focus on improving the project for others.