I\'m using an API that returns JSON that looks like this
{
\"boards\":[
{
\"attribute\":\"value1\"
},
{
\"attribute\":
Take a look here:https://github.com/lingoer/SwiftyJSON
let json = JSONValue(dataFromNetworking)
if let userName = json[0]["user"]["name"].string{
//Now you got your value
}
Dictionary access in Swift returns an Optional, so you need to force the value (or use the if let
syntax) to use it.
This works:
parsedJSON["boards"]![0]
(It probably shouldn't crash Xcode, though)
You can create a variable
var myBoard: NSArray = parsedJSON["boards"] as! NSArray
and then you can access whatever you have in "boards" like-
println(myBoard[0])
The correct way to deal with this would be to check the return from the dictionary key:
if let element = parsedJSON["boards"] {
println(element[0])
}