Python json Pickle

Source: Internet
Author: User

Two modules for serialization in Python

    • JSON is used to convert between "string" and "Python Basic data Types"

    • Pickle for "Python-specific type" and "Python basic data type" to convert between

The JSON module provides four functions: dumps, dump, loads, load

The Pickle module provides four functions: dumps, dump, loads, load

Import jsons = ' {' key ': ' Value '} ' dic = Json.loads (s) str = json.dumps (DIC) print (Dic,type (DIC)) print (Str,type (str)) Result: {' Key ': ' Value '} <class ' Dict ' >{"key": "Value"} <class ' str ' >

If you are dealing with files instead of strings, you can use json.dump() and json.load() encode and decode JSON data. For example:

# Writing JSON datawith open (' Data.json ', ' W ') as F:json.dump (data, f) # Reading Data Backwith open (' Data.json ', ' R ') a s f:data = Json.load (f) Pickle used to convert between Python-specific type and Python base data type

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/82/7D/wKioL1dWy6HR6HYuAABUpCNKHV0201.png-wh_500x0-wm_3 -wmp_4-s_1907122844.png "title=" 425762-20151114231017087-842020084.png "alt=" Wkiol1dwy6hr6hyuaabupcnkhv0201.png-wh_50 "/>

Python json Pickle

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.