栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

将多维度Json数组解析为Python

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

将多维度Json数组解析为Python

解析JSON之后,您将得到一个Python dict。因此,假设上述JSON位于名为input_data的字符串中:

import json# This converts from JSON to a python dictparsed_input = json.loads(input_data)# Now, all of your static variables are referenceable as keys:secret = parsed_input['secret']minutes = parsed_input['minutes']link = parsed_input['link']# Plus, you can get your bookmark collection as:bookmark_collection = parsed_input['bookmark_collection']# Print a list of names of the bookmark collections...print bookmark_collection.keys() # Note this contains sublinks, so remove it if needed# Get the name of the Boarding Pass bookmark:print bookmark_collection['boarding_pass']['name']# Print out a list of all bookmark links as:#  Boarding Pass#    * 1: http://www.1.com/#    * 2: http://www.2.com/#  ...for bookmark_definition in bookmark_collection.values():    # Skip sublinks...    if bookmark_definition['name'] == 'sublinks':        continue    print bookmark_definition['name']    for bookmark in bookmark_definition['bookmarks']:        print "    * %(name)s: %(link)s" % bookmark# Get the sublink definition:sublinks = parsed_input['bookmark_collection']['sublinks']# .. and print themprint sublinks['name']for link in sublinks['link']:    print '  *', link


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/517064.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号