I call the JSON API, which has a few nested values ββthat I need to get. I use SwiftyJSON to make things a little cleaner. For the top-level values, everything seems to work fine, but with something deeper, I get the scary "zero when expanding the extra value."
Here's how I make an API call using Alamofire:
Alamofire.request(APIRequests.Router.Nearby(self.page)).responseJSON(){ (_,_,json,_) in println(json) if (json != nil){ var jsonObj = JSON(json!) if let userArray = jsonObj ["results"].array { for userDict in userArray { var username: String! = userDict["username"].string var firstName: String! = userDict["firstName"].string var profileImage: String! = userDict["userImages"]["profile"]["filename"].string var characterName: String! = userDict["characters"]["characterName"].string var user = User(username: username, profileImage: profileImage, firstName: firstName, characterName: characterName) self.users.append(user) } }
Here is a JSON example:
{ userInfo: { something: "abc", requestType: "GET" }, results: [ { username: "Jess", firstName: "Jessica", userImages: { profile: [ { userImageID: "6", filename: "user-07.jpg" } ], cover: [ { userImageID: "15", filename: "user-07.jpg" } ] }, characters: [ { userCharacterID: "8", characterName: "Amelia", } ] }
For the top-level keys username and firstName debugger shows the correct values, however, as soon as I dive a bit to get profileImage or characterName , they return as zero, although the json print shows the values ββfor these keys.
What am I doing wrong? I just don't see it.
Any thoughts will be helpful. Thanks.