Python cross-language data interaction, Json,pickle (serialization).

Source: Internet
Author: User
Tags serialization

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

Json.dudmp ("[11,22]", open (' Db.txt ', ' W ')) #转换成字符串再保存到该文件.

Json.load (Open (' Db.txt ', ' R ')) #打开该文件装成字符串.

Import JSON
s= "{" K1 ":" 123 "}" #注, the characters in the dictionary must be enclosed in double quotation marks before they can be converted to JSON.
L="[11,22,33,44]"= json.loads (1) #用于将字典, list, tuple form strings into dictionaries, lists, tuples.
st = Json.dumps (l) # Converts the list to a JSON-formatted string.
Print (Result,type (Result))

Receives a value from an interface. py

Import urllib.request Import JSON req   = Urllib.request.Request ('http://www.baidu.com/api ")r == str (R.read (), encoding="  utf-8"= json.load (reesult)print (DIC)

Python cross-language data interaction, Json,pickle (serialization).

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.