我如何使用 swift3 解析这个 JSON 数据。我正在尝试将其转换为 [String: Any] 字典。
我正在使用 JSONSerialization 来解析此数据,但无法正确解析。这些数据有嵌套的字典,我该如何解析?谁能帮我解决这个问题?
{
"info": {
"imdb_id": "",
"movie_image": "http://abc/images/2072233.jpg",
"genre": "Action / Crime / Thriller",
"plot": "Il est prêt à tout pour sauver son fils et il n’a qu’une nuit devant lui.",
"cast": "JMatthew Cornwell / Marisol Correa / Stephen Dean / Rayshaun Deese / Deborah Wilkins / Derrick Worsley",
"rating": "5.6",
"director": "Baran bo Odar",
"releasedate": "9 août 2017",
"duration_secs": 5691,
"duration": "01:34:51",
"video": {
"index": 0,
"time_base": "1/16000",
"start_pts": 672,
"start_time": "0.042000",
"duration_ts": 91070976,
"duration": "5691.936000",
"bit_rate": "4537543",
"bits_per_raw_sample": "8",
"nb_frames": "136469",
"disposition": {
"default": 1,
"attached_pic": 0,
"timed_thumbnails": 0
},
"tags": {
"language": "eng",
"handler_name": "VideoHandler"
}
},
"audio": {
"index": 2,
"bits_per_sample": 0,
"dmix_mode": "-1",
"ltrt_cmixlev": "-1.000000",
"ltrt_surmixlev": "-1.000000",
"loro_cmixlev": "-1.000000",
"loro_surmixlev": "-1.000000",
"r_frame_rate": "0/0",
"nb_frames": "177873",
"disposition": {
"default": 0,
"dub": 0,
"original": 0,
"timed_thumbnails": 0
},
"tags": {
"language": "eng",
"handler_name": "SoundHandler"
},
"side_data_list": [
{
"side_data_type": "Audio Service Type"
}
]
},
"bitrate": 5058
}
}
//How can i parse this JSON data using swift3
//I am using JSONSerialization to parse this data but not able to correctly parse. This data have nested dictionaries how can i parse this?
很难从您在评论中发布的内容中辨别出来,但这里用于解析 imdb_id:
super.httpRequest(params: requestDict) { (responseData) in
guard let data = responseData else { return }
do {
let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]
if let info = json["info"] as? [String: Any] {
let id = info["imdb_id"] as? String
print("The imdb_id is \(id)")
}
} catch let error as NSError {
print(error)
}
}
你看到打印出来的是什么?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句