iOSNewbie iOSNewbie - 1 year ago 67
JSON Question

How to convert JSON to Object and save it to Array

i got JSON in format like that:

"person": {
"name": "Dani",
"age": "24"
"person": {
"name": "ray",
"age": "70"

I want to create object of that and storage it in array, how can i do it? I use Alamofire and SwiftyJSON.

Answer Source

Using SwiftyJSON, you can convert JSON data to an array like following:

Suppose feedData is the JSON, you want to convert:

    do {
           let jsonDataToParse = try NSJSONSerialization.dataWithJSONObject(feedData, options: NSJSONWritingOptions.PrettyPrinted)
           let jsonData = JSON(data: jsonDataToParse)
           if let DataArray = jsonData.array{
                // use your array
       }catch let error as NSError{
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download