D. Rao D. Rao - 4 months ago 27
iOS Question

iOS: SwiftyJSON parsing from Alamofire is an array. Getting null when trying to parse

the api request returns something like this:


I am using swiftyJSON to parse this, I got data from Alamofire request:

let json = JSON(data)
let mapHeir = json[0]["hatInfo"]["hatHierarchyString"]

This returns null, I tried:

let mapHeir = json[0]["hatInfo"]["hatHierarchyString"].string
let mapHeir = json[0]["hatInfo"]["hatHierarchyString"].stringValue
let mapHeir = json["hatInfo"]["hatHierarchyString"]

and all of them return empty.
How can I get to hatHierarchyString?


Try this:

Suppose you've something like:

.responseJSON{ response in

switch response1.result{
                    case .Success:
            let json = JSON(data: response.data!)

Then do,

if let someThing = json[0]["hatInfo"]["hatHierarchyString"].string {
  //Now you got your value