当前位置: 移动技术网 > IT编程>脚本编程>Python > Python操作json数据的一个简单例子

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

2019年03月31日  | 移动技术网IT编程  | 我要评论

指付通官网,江南都市报电子版,痞子白领

更多的信息,可以参考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代码检验、检验、美化、格式化工具:

json在线格式化工具:

在线xml/json互相转换工具:

json代码在线格式化/美化/压缩/编辑/转换工具:

在线json压缩/转义工具:

c语言风格/html/css/json代码格式化美化工具:

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网