更多的信息,可以参考python内部的json文档:
python>>> help(json)
或者官方文档:
http://docs.python.org/library/json.html#module-json 下面给出一个使用python解析json的简单例子:
1. #!/usr/bin/python
2. import json
3. #Function:Analyze json script
4. #Json is a script can descript data structure as xml,
5. #for detail, please refer to "http://json.org/json-zh.html".
6.
7. #Note:
8. #1.Also, if you write json script from python,
9. #you should use dump instead of load. pleaser refer to "help(json)".
10.
11. #json file:
12. #The file content of temp.json is:
13. #{
14. # "name":"00_sample_case1",
15. # "description":"an example."
16. #}
17. #f = file("temp.json");
18. #s = json.load(f)
19. #print s
20. #f.close
21.
22. #json string:
23. s = json.loads('{"name":"test", "type":{"name":"seq", "parameter":["1", "2"]}}')
24. print s
25. print s.keys()
26. print s["name"]
27. print s["type"]["name"]
28. print s["type"]["parameter"][1]
说明一下,我在按上边的这个方法解析从客户端发过来的json数据时一直出问题,总是解析不出来,后边才发现,json格式的字符串是不能用'(单引号)来表示字符串的,字符串必须用"(双引号),所以在我的代码中使用了str.replace('\'','\"')后就可以正常解析了。