JSON and Pickle modules

Source: Internet
Author: User

The results of #json module output are JSON strings that can be recognized by other languages
Import JSON
A = {' name ': ' Alex '} #------->{"name": "Alex"}-----------> ' {"name": "Alex"} '
b = 9 #----------> ' 9 '
c = ' Hello ' #--------> "Hello"---------> ' "Hello"
D = [11,22] #------' [11,22] '

Print (Json.dumps (a)) #将对象封装成json字符串
A = {' name ': ' Liuhaiquan '}
A_j = Json.dumps (a)
With open (' a.txt ', ' r+ ') as F_read:
F_read.write (A_j)

With open (' A.txt ', ' R ') as F_read:
data = F_read.read ()
Print (json.loads (data)) #提取字符串内的字典
Print (Type json.loads (data))
------------------------------------------


#pickle的用法和json一样, but the result of pickle.dumps () processing is byte bytes
Need to use RB when reading bytes

But pickle supports more data types, usually JSON uses more




JSON and pickle modules

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.