python3.7 JSON module

Source: Internet
Author: User
Tags serialization

#!/usr/bin/env python__author__="lrtao2010" #python3.7 JSON module" "to pass an object between different programming languages, you must serialize the object into a standard format, such as XML, but a better way is to serialize it to JSON, because JSON represents a string that can be read by all languages, easily stored to disk, or transmitted over a network. JSON is not only a standard format, but also faster than XML, and can be read directly in the Web page, very convenient. " "" "the process by which objects (variables) become stored or transferred from memory is called serialization, and after serialization, the serialized content can be written to disk or transmitted over a network to another machine. In turn, re-reading the variable contents from the serialized object into memory is called deserialization. " "#JSON rules" "1, the string must use "", single quotation mark error, 2, no matter how the data is created, as long as the JSON format, you can json.loads out, not necessarily dumps data to loads. " "ImportJSON#dic = {' name ': ' Test ', ' age ':#json_dic = json.dumps (DIC)#Print (Json_dic,type (json_dic))#{"Name": "Test", "Age": <class ' str ' >#dic = ' {' name ': ' Test ', ' age ': '#json_dic = json.loads (DIC)#Print (Json_dic,type (json_dic))#{' name ': ' Test ', ' age ': <class ' dict ' >#json_f = ' Json_text.txt '#json_dic = {' name ': ' Test ', ' age ':#with open (Json_f, ' W ') as F:#F.write (Json.dumps (json_dic)) #等同于json. Dump (json_dic,f), dump can only be used to write to disk. #With Open (Json_f) as F:#my_dic=json.loads (F.read ()) #等同于my_dic =json.load (f), load can only be used to read from disk##print (my_dic[' name '])#Test

python3.7 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.