使用python解析json文件
转自:http://blog.chinaunix.net/uid-9525959-id-3074355.html更多的信息,可以参考python内部的json文档:python>>> help(json)或者官方文档:http://docs.python.org/library/json.html#module-json下面给出一个使用python解析json的简单例子:
·
转自:http://blog.chinaunix.net/uid-9525959-id-3074355.html
更多的信息,可以参考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]
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐

所有评论(0)