需要解析的 json 是这个: www.zimuzu.tv/resource/index_json/rid/33701/channel/tv (去掉首行的"var index_info=")
可以在 http://tool.oschina.net/codeformat/json 进行可视化
相关代码是这样
let json = try? JSONSerialization.jsonObject(with: data, options: [])
if let dictionary = json as? [String: Any] {
if let array = dictionary["prevue"] as? NSArray {
print(array[0])
}
}
问题是:
- 我如何确定 JSONSerialization.jsonObject(with:options:) -> Any 返回的具体类型?
- 为什么 dictionary["prevue"]无法转换成[String: Any]? 我如何确定 dictionary["prevue"]的具体类型?
- 在把 dictionary["prevue"]转换成 NSArray 后, print("array[0]")的输出, key 值两边的双引号为什么不见了?
{
episode = 9;
"play_time" = "2016-11-28";
season = 1;
t = 1480348800;
week = "\U5468\U4e00";
}
附:官方博客对 JSONSerialization 的示范代码 : developer.apple.com/swift/blog/?id=37

