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