Turn from: http://blog.chinaunix.net/uid-9525959-id-3074355.html
For more information, refer to the JSON documentation within Python: python>>> Help (JSON)
or official documents:
Http://docs.python.org/library/json.html#module-json
Here's a simple example of using Python to parse 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]