您的位置:首页 > 编程语言 > Python开发

使用python解析json文件

2013-06-24 15:23 736 查看
更多的信息,可以参考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]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: