Python JSON module

Source: Internet
Author: User

The dumps () function, the loads () function, the dump () function, the load () function are mainly in the JSON module.

JSON returns a string type with high readability, which differs from pickle.

There are limitations, no serialization of time formats, etc., pickle can serialize data in any format, but Python-specific, JSON supports multiple languages.

#json. Dumps (' object ')     #序列化对象, return string type
#json. Dump (' object ', f) #序列化对象到文件中
#json. Loads (' object ') #反序列化对象
#json. Load (f) #从文件中反序列对象, return to the original object

Import jsonobj = 123, "Abcdedf", ["AC", 123],{"key": "Value", "Key1": "Value1"} #json. Dumps (' object ')     #序列化对象, Returns a string of type #json.dump (' object ', f)      #序列化对象到文件中 #json.loads (' object ')     #反序列化对象 #json.load (f)     #从文件中反序列对象, Returns the original OBJECTR1 = Json.dumps (obj) print (r1) r2 = json.loads (r1) print (R2) with open (' db ', ' W ') as F:    json.dump (obj, f) With open (' db ', ' R ') as F:    r3 = Json.load (f)    print (R3)

Python JSON module

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.