如何用Python解析Json文件
发布网友
发布时间:2022-04-19 15:06
我来回答
共1个回答
热心网友
时间:2022-04-18 05:22
下面给出一个使用python解析json的简单例子:
#!/usr/bin/python
import json
#Function:Analyze json script
#Json is a script can descript data structure as xml,
#Note:
#1.Also, if you write json script from python,
#you should use mp 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]