7--1 JSON module

Source: Internet
Author: User

Exchange between any languages

1 Import JSON 2   3 dic={' name ': ' Alvin ', ' Age ':, ' sex ': ' Male '} 4 print (Type (DIC)) #<class ' Dict ' > 5   6 j= Json.dumps (DIC) 7 print (Type (j)) #<class ' str ' > 8   9  f=open (' serialized object ', ' W ') F.write (j)  #---------- ---------is equivalent to Json.dump (dic,f) f.close ()-----------------------------deserialization <br>14 import json15 f=open (' Serialized object ') Data=json.loads (F.read ()) #  equivalent to Data=json.load (f)

If we are going to pass objects between different programming languages, we have to serialize the object into a standard format, such as XML, but the 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.

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