1

I have this JSON (this is a simplified version):

{
   "from":0,
   "location": [{
       "city":"Barcelona"
       }]
}

And i'm trying to do an Alamofire request with this JSON on parameters. So I have typed something like this:

let parameter = [
  "from":0,
  "location": [
   ["city": "Barcelona"] 
  ]
]

But it seems Alamofire doesn't accept the parse from [{ }] to [[]] on parameters. I have read that one way to solve this is using a MutableURLRequest but i don't find any clear example.

Alamofire.request(.GET, "http://myurl", parameters: (params as! [String : AnyObject]), headers: nil).responseCollection { (response: Response<[Group], NSError>) in
switch response.result {
            case .Success(let groups):
                print("Success")
            case .Failure(_):
                print("Failure")
            }
        }

This code above works and I get a result from this Alamofire Request but ignores this:

"location": [ ["city": "Barcelona"]]

Could someone can help with that? Thank you so much.

Eironeia
  • 771
  • 8
  • 20
  • May be this will help you http://stackoverflow.com/questions/27026916/sending-json-array-via-alamofire – Nirav D Oct 04 '16 at 11:11
  • I get this error with this code @NiravD: – Eironeia Oct 04 '16 at 13:30
  • Error Domain=NSURLErrorDomain Code=-1017 "no se puede analizar la respuesta" UserInfo={NSUnderlyingError=0x7fcacfa367a0 {Error Domain=kCFErrorDomainCFNetwork Code=-1017 "(null)" UserInfo={_kCFStreamErrorCodeKey=-1, _kCFStreamErrorDomainKey=4}} – Eironeia Oct 04 '16 at 13:31

0 Answers0