Python JSON module

Source: Internet
Author: User
First, the JSON format introduction

The JSON format is a lightweight data interchange format that is easily identifiable and machine-parsed, and its full name is called JavaScript Object Notation.

The JSON module provides an API interface similar to the Pickle Persistence module, which converts the in-memory Python object to a serialized representation, called JSON. JSON is the most widely used in AJAX applications in the communication between the Web server and the client, but also in the application of other programs.

Second, the JSON module encoding

Play Snake network Leo here using the Json.dumps method, a Python data type list is encoded in JSON format,
Examples are as follows:

>>> Import JSON #导入json格式
>>> L = [' Iplaypython ', [n/a], {' name ': ' Xiaoming '}] #创建一个l列表
>>> Encoded_json = Json.dumps (l) # List of L, JSON format encoding
>>> print repr (i)
>>> Print Encoded_json #输出结果

This allows us to convert a list object into a JSON-formatted encoding.

Third, the JSON module decoding

Decoding JSON format, you can use the Json.loads () function of this module to parse the method,
Examples are as follows:

>>> Decode_json = json.loads (Encoded_json)
>>> print Type (Decode_json) #查看一下解码后的对象类型
>>> Print Decode_json #输出结果
>>>

Python JSON module

Related Article

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.