[Tips] python json parsing

The python string contents parsed into objects, and converting the object to a string python content, use:

json.loads (text string) 
json.dumps (Python objects) 
# to python3
Import JSON

Data} = {
json_str = json.dumps (Data)
Print ( " the Python raw data: " , the repr ( DATAl ) ) Print ( " the JSON Object : " , json_str )


data1 = json . loads ( json_str )

  

If the file is processed, use:

the json.load (file handle) 
The json.dump (Python object file handle) 

with Open ( ' the data.json ' , ' W ' ) AS F : JSON . the dump ( Data , F ) with Open ( ' the data.json ' , ' R & lt ' ) AS F : Data = JSON . Load ( F )



  

Guess you like

Origin www.cnblogs.com/immortalBlog/p/11510788.html