V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
HannibaI
V2EX  ›  问与答

初学 iOS,关于 JSONSerialization 行为的问题?

  •  
  •   HannibaI · 2016-11-23 09:05:30 +08:00 · 1058 次点击
    这是一个创建于 2712 天前的主题,其中的信息可能已经有所发展或是发生改变。

    需要解析的 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

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2642 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 05:02 · PVG 13:02 · LAX 22:02 · JFK 01:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.