加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

Python操作json数据的一个简单例子

发布时间:2020-12-16 19:50:48 所属栏目:Python 来源:网络整理
导读:更多的信息,可以参考python内部的json文档: python help(json) 或者官方文档: http://docs.python.org/library/json.html#module-json. 下面给出一个使用python解析json的简单例子: 复制代码 代码如下: #!/usr/bin/python import json #Function:Analyze

更多的信息,可以参考python内部的json文档:
python>>> help(json)
或者官方文档: http://docs.python.org/library/json.html#module-json.

下面给出一个使用python解析json的简单例子:

复制代码 代码如下:

#!/usr/bin/python
import json
#Function:Analyze json script
#Json is a script can descript data structure as xml,
#for detail,please refer to "http://json.org/json-zh.html".

#Note:
#1.Also,if you write json script from python,
#you should use dump instead of load. pleaser refer to "help(json)".

#json file:
#The file content of temp.json is:
#{
# "name":"00_sample_case1",
# "description":"an example."
#}
#f = file("temp.json");
#s = json.load(f)
#print s
#f.close

#json string:
s = json.loads('{"name":"test","type":{"name":"seq","parameter":["1","2"]}}')
print s
print s.keys()
print s["name"]
print s["type"]["name"]
print s["type"]["parameter"][1]

PS:关于json操作,这里再为大家推荐几款比较实用的json在线工具供大家参考使用:

在线JSON代码检验、检验、美化、格式化工具:
http://tools.aspzz.cn/code/json

JSON在线格式化工具:
http://tools.aspzz.cn/code/jsonformat

在线XML/JSON互相转换工具:
http://tools.aspzz.cn/code/xmljson

json代码在线格式化/美化/压缩/编辑/转换工具:
http://tools.aspzz.cn/code/jsoncodeformat

在线json压缩/转义工具:

http://tools.aspzz.cn/code/json_yasuo_trans

C语言风格/HTML/CSS/json代码格式化美化工具:
http://tools.aspzz.cn/code/ccode_html_css_json

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读