如何用Python解析Json文件

下面给出一个使用python解析json的简单例子:#!/usr/bin/pythonimport 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 ...
如何用Python解析Json文件
下面给出一个使用python解析json的简单例子:#!/usr/bin/pythonimport 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 sprint s.keys()print s["name"]print s["type"]["name"]print s["type"]["parameter"][1]2016-10-31
mengvlog 阅读 715 次 更新于 2025-10-29 21:49:19 我来答关注问题0
檬味博客在线解答立即免费咨询

Python相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部