How to pass to Array JSON information in Swift

1

When the result comes from the server I use the following code snippet to get the result:

if let JSON = response.result.value {
      print("JSON: \(JSON)")
}

And the print result is:

[{
  Nome = Tiago;
  Idade = 22;
  Cidade = Minas;
}, {
  Nome = Luisa;
  Idade = 12;
  Cidade = Califórnia;
}]

How can I do to get this result and put it in an array?

    
asked by anonymous 12.02.2016 / 16:23

1 answer

2

You can create a String array and get the json result with it and then use it in another method.

Declare in global scope, this is at the beginning of the class: var texto: [String] = []

Then when I go through Json to get the value of each item from an append on it:

Alamofire.request(mutableURLRequest).responseJSON {
  response in
if
  let value: AnyObject = response.result.value {
let json = JSON(value) print(json) for (_, subJson) in json {
  self.texto.addObject(subJson.object)
}
  }
}
    
12.02.2016 / 16:29