Buenas tardes, estoy usando la API de Spotify, intento acceder a este Json:
He podido acceder satisfactoriamente al valor "name", pero quisiera acceder al arreglo "images" y su valor "url", entonces específicamente mi pregunta sería, ¿Cómo acceder a "images" y obtener el valor "url"?
{
"artists" : [ {
"external_urls" : {
"spotify" : "https://open.spotify.com/artist/2CIMQHirSU0MQqyYHq0eOx"
},
"followers" : {
"href" : null,
"total" : 1685704
},
"genres" : [ "big room", "brostep", "edm", "electro house", "progressive house" ],
"href" : "https://api.spotify.com/v1/artists/2CIMQHirSU0MQqyYHq0eOx",
"id" : "2CIMQHirSU0MQqyYHq0eOx",
"images" : [ {
"height" : 640,
"url" : "https://i.scdn.co/image/86e8991077d6ce237be8f24dbc65e90f2e1f2a43",
"width" : 640
}, {
"height" : 320,
"url" : "https://i.scdn.co/image/cd362662352ce88b693b1a31cf5c9784730291dd",
"width" : 320
}, {
"height" : 160,
"url" : "https://i.scdn.co/image/70e010473dc0f158253111e035c71086fb7904fa",
"width" : 160
} ],
"name" : "deadmau5",
"popularity" : 71,
"type" : "artist",
"uri" : "spotify:artist:2CIMQHirSU0MQqyYHq0eOx"
}, {
"external_urls" : {
"spotify" : "https://open.spotify.com/artist/57dN52uHvrHOxijzpIgu3E"
},
"followers" : {
"href" : null,
"total" : 355935
},
"genres" : [ "alternative dance", "brooklyn indie", "electronic", "indie pop", "indietronica", "new rave" ],
"href" : "https://api.spotify.com/v1/artists/57dN52uHvrHOxijzpIgu3E",
"id" : "57dN52uHvrHOxijzpIgu3E",
"images" : [ {
"height" : 693,
"url" : "https://i.scdn.co/image/2f0c6c465a83cd196e651e3d4e7625ba799a6f60",
"width" : 1000
}, {
"height" : 444,
"url" : "https://i.scdn.co/image/4e3e13c8b993bde9898e49509fb9ae121636e05f",
"width" : 640
}, {
"height" : 139,
"url" : "https://i.scdn.co/image/dc68dd24b45b74ecce9d4ed486423673d683ced3",
"width" : 200
}, {
"height" : 44,
"url" : "https://i.scdn.co/image/4e55ca05d4f336a2fa0e3062a7ec9778a201e8bc",
"width" : 63
} ],
"name" : "Ratatat",
"popularity" : 70,
"type" : "artist",
"uri" : "spotify:artist:57dN52uHvrHOxijzpIgu3E"
} ]
}
Y este es el código que estoy usando en iOS Swift 3:
let url = "https://api.spotify.com/v1/artists?ids=6XyY86QOPPrYVGvF9ch6wz,74XFHRwlV6OrjEM0A2NCMF,12Chz98pHFMPJEknJQMWvI,6IdtcAwaNVAggwd6sCKgTI,2af5rOpTISbX2YSVYiqoFJ,0yNSzH5nZmHzeE2xn6Xshb,1GImnM7WYVp95431ypofy9,2F9pvj94b52wGKs0OqiNi2,27Owkm4TGlMqb0BqaEt3PW,7oPftvlwr6VrsViSDV7fJY"
var gruposObtenidos: NSMutableArray = []
@IBOutlet var gruposTabNormal: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
if WebServiceController.conexionInternet(){
WebServiceController.sharedInstance.callUrlWithCompletion(url: url, params: nil, completion: { (finished, response) in
if finished{
//print(response)
//Para nombre de los grupos
let resultadoJson = NSMutableArray(array: response["artists"] as! NSArray)
self.gruposObtenidos = resultadoJson
self.gruposTabNormal.reloadData()
}else{
print("Sin conexión con el servidor")
}
}, method: .get)
}else{
print("No hay internet")
}
}
Este es mi controlador de la celda del UICollectionView:
class CancionesNormalesCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var imgGrupo: UIImageView!
@IBOutlet weak var txtNombreGrupo: UILabel!
var grupos: Dictionary<String, AnyObject>!
func iniciarCelda(){
let nombreGrupo = self.grupos["name"] as! String
self.txtNombreGrupo.text = nombreGrupo
}
}