¿Cómo puedo analizar json con más de un valor?

Estoy intentando analizar un file json en mi código. Hasta ahora he logrado hacerlo a exception de una key (género) que tiene una matriz de valores. ¿Quiero saber cómo puedo analizarlo para poder presentarlo en un UILabel?

JSON File: [{ "title": "Dawn of the Planet of the Apes", "image": "http://api.androidhive.info/json/movies/1.jpg", "rating": 8.3, "releaseYear": 2014, "genre": ["Action", "Dtwig", "Sci-Fi"] }, { "title": "District 9", "image": "http://api.androidhive.info/json/movies/2.jpg", "rating": 8, "releaseYear": 2009, "genre": ["Action", "Sci-Fi", "Thriller"] }, { "title": "Transformers: Age of Extinction", "image": "http://api.androidhive.info/json/movies/3.jpg", "rating": 6.3, "releaseYear": 2014, "genre": ["Action", "Adventure", "Sci-Fi"] }, { "title": "X-Men: Days of Future Past", "image": "http://api.androidhive.info/json/movies/4.jpg", "rating": 8.4, "releaseYear": 2014, "genre": ["Action", "Sci-Fi", "Thriller"] }, { "title": "The Machinist", "image": "http://api.androidhive.info/json/movies/5.jpg", "rating": 7.8, "releaseYear": 2004, "genre": ["Dtwig", "Thriller"] }, { "title": "The Last Samurai", "image": "http://api.androidhive.info/json/movies/6.jpg", "rating": 7.7, "releaseYear": 2003, "genre": ["Action", "Dtwig", "History"] }, { "title": "The Amazing Spider-Man 2", "image": "http://api.androidhive.info/json/movies/7.jpg", "rating": 7.3, "releaseYear": 2014, "genre": ["Action", "Adventure", "Fantasy"] }, { "title": "Tangled", "image": "http://api.androidhive.info/json/movies/8.jpg", "rating": 7.9, "releaseYear": 2010, "genre": ["Action", "Dtwig", "Sci-Fi"] }, { "title": "Rush", "image": "http://api.androidhive.info/json/movies/9.jpg", "rating": 8.3, "releaseYear": 2013, "genre": ["Animation", "Comedy", "Family"] }, { "title": "Drag Me to Hell", "image": "http://api.androidhive.info/json/movies/10.jpg", "rating": 6.7, "releaseYear": 2009, "genre": ["Horror", "Thriller"] }, { "title": "Despicable Me 2", "image": "http://api.androidhive.info/json/movies/11.jpg", "rating": 7.6, "releaseYear": 2013, "genre": ["Animation", "Comedy", "Family"] }, { "title": "Kill Bill: Vol. 1", "image": "http://api.androidhive.info/json/movies/12.jpg", "rating": 8.2, "releaseYear": 2003, "genre": ["Action", "Crime"] }, { "title": "A Bug's Life", "image": "http://api.androidhive.info/json/movies/13.jpg", "rating": 7.2, "releaseYear": 1998, "genre": ["Animation", "Adventure", "Comedy"] }, { "title": "Life of Brian", "image": "http://api.androidhive.info/json/movies/14.jpg", "rating": 8.9, "releaseYear": 1972, "genre": ["Comedy"] }, { "title": "How to Train Your Dragon", "image": "http://api.androidhive.info/json/movies/15.jpg", "rating": 8.2, "releaseYear": 2010, "genre": ["Animation", "Adventure", "Family"] }] Movie Class import UIKit class Movie { var title = "" var image = "" var rating = 0.0 var releaseYear = 0 init(object: [String: AnyObject]) { self.title = object["title"] as! String self.image = object["image"] as! String self.rating = object["rating"] as! Double self.releaseYear = object["releaseYear"] as! Int } init() { } } MovieCell Class import UIKit 

importar SDWebImage

class MovieCell: UITableViewCell {

 @IBOutlet weak var titleLbl: UILabel! @IBOutlet weak var releaseYearLbl: UILabel! @IBOutlet weak var ratingLbl: UILabel! @IBOutlet weak var movieImage: UIImageView! @IBOutlet weak var genreLbl: UILabel! override func awakeFromNib() { super.awakeFromNib() } func createCell(movie: Movie) { self.titleLbl.text = movie.title self.releaseYearLbl.text = "\(movie.releaseYear)" self.ratingLbl.text = "\(movie.rating) ⭐️" movieImage.layer.cornerRadius = 10.0 movieImage.clipsToBounds = true self.movieImage.sd_setImage(with: URL(string: movie.image)) } override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) // Configure the view for the selected state } 

}

Swift 3.0

Simplemente analice el código a continuación y aplíquelo a su problema.

La class de Movie convierte,

 class Movie { var title = "" var image = "" var rating = 0.0 var releaseYear = 0 var genre:String? init(object: [String: AnyObject]) { self.title = object["title"] as! String self.image = object["image"] as! String self.rating = object["rating"] as! Double self.releaseYear = object["releaseYear"] as! Int let genreArray = object["genre"] as! [String] /*Whatever you want do here with genre. I thought you need whole array to one readable String*/ for strings in genreArray{ self.genre = self.genre == nil ? strings : self.genre!+" "+strings } } } 

Clase que tenía UITableView

La variable global de la class es,

 var movieData = Array<Movie>() 

El JSON parse will se convierte,

 if let json = try! JSONSerialization.jsonObject(with: data, options: .allowFragments) as? Array<Dictionary<String, AnyObject>>{ for object in json{ self.movieData.append(Movie(object: object)) } DispatchQueue.main.async { self.tableView.reloadData() } 

UITableView datasource

 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return movieData.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = self.tableView.dequeueReusableCell(withIdentifier: "cell", for:indexPath) let tableObject:Movie = self.movieData[indexPath.row] cell.textLabel?.text = tableObject.genre //This way you will be get all values and apply it to whatever you want... return cell } 

SALIDA:-

introduzca la descripción de la imagen aquí