私は残りのWebサービスを消費しようとしている...解析JSON - Alamofire
私のJSON応答の構造は次のとおりです。
"page": 1,
"results": [
{
"poster_path": "/9Hj2bqi955SvTa5zj7uZs6sic29.jpg",
"adult": false,
"overview": "",
"release_date": "2015-03-15",
"genre_ids": [
99
],
"id": 441580,
"original_title": "The Jinx: The Life and Deaths of Robert Durst Season 1 Chapter 6: What the Hell Did I Do?",
"original_language": "en",
"title": "The Jinx: The Life and Deaths of Robert Durst Season 1 Chapter 6: What the Hell Did I Do?",
"backdrop_path": "/3br0Rt90AkaqiwVBZVvVUYD1juQ.jpg",
"popularity": 1,
"vote_count": 1,
"video": false,
"vote_average": 10
}
],
"total_results": 307211,
"total_pages": 15361
}
は、私がページと結果の配列を取得しようとしています...解析後はページ(paginationCount)と結果(jsonArray)変数はnilです。私のコードは
あります:あなたはポストの要求を持っている場合
Alamofire.request(ConstantHelper.kUrlDiscoverMovies, method: .get, parameters: ["api_key": ConstantHelper.kApiKey, "certification" : average, "sort_by" : "vote_average.desc" ]).validate()
.responseJSON { response in
switch response.result {
case .success:
if let repoJSON = response.result.value as? JSON {
let jsonArray = repoJSON["results"] as? NSMutableArray
for item in jsonArray! {
guard let movie = Movie(json: item as! JSON) else
{
print("Issue deserializing model")
return
}
listMovies.append(movie)
}
if let paginationCount = repoJSON["total_pages"] as? String {
completion(listMovies, Int(paginationCount)!, nil)
}
else {
completion(listMovies, 0, nil)
}
}
break
case .failure(let error):
completion(nil, 0, error as NSError?)
break
}
}
解析後ですか?どこ?成功の封鎖の中で、それは動作しますか? – Larme
成功のクロージャ内... paginationCountをnilにする – Developer2012