A simple example of using Python to operate json data

Source: Internet
Author: User

For more information, refer to the json document in python:
Python >>> help (json)
Or official document: http://docs.python.org/library/json.html#module-json.

The following is a simple example of using python to parse json:
Copy codeThe Code is as follows:
#! /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 shoshould 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]

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.