JSON object with Array. Migration from swift 2 to swift 3

0

Previously in my app when I was making a call to the server and if there was an error I would do the following:

Alamofire.request(mutableURLRequest).responseJSON{
response in if let JSON = response.result.value{
if JSON.count != 0{
let errorList = JSON["responseErrorsList"] as? NSArray
 for error in errorList!{
   let erro: String = error as! String
     switch erro{
       case "EntityRequired":

With the migration from swift 2 to swift 4 I am having problems because theList errors comes to nil however the result of JSON is as follows:

["Rate":, "Level":, "Code":, "ID": 0, "Zone":, "Address":, "ErrorsListServer": ( InvalidCode ) , "SubZone":]

Someone knows how I can access the "ErrorsListServer" field and fetch the errors that in this case is "InvalidCode".

What I have implemented and is not working for is the following:

if let JSON = response.result.value as? [String: Any]{
    if (JSON as AnyObject).count != 0{
      let errorList = JSON["responseErrorsList"] as? [[String: Any]]
    
asked by anonymous 18.01.2017 / 16:38

1 answer

0

I found answer to my question bas do the following:

if let JSON = response.result.value as? [String: Any], 
let errorList = JSON["ErrorsListServer"] as? [String] {
  for error in errorList {
      print(error)
  }
}
    
23.01.2017 / 13:41