python json mutual conversion and dictionary objects

 

Requests Import 
Import json 
'' '
 conversion json.loads (json_str) json string into a dictionary 
is converted into a string json json.dumps (dict) Dictionary 

' ''
 # This is a get request initiated ajax obtain a target json 
R & lt = Requests. GET ( " https://m.douban.com/rexxar/api/v2/subject_collection/movie_showing/items?os=ios&for_mobile=1&start=0&count=18&loc_id=108288&_=0 " ) 
json_response = r.content.decode ( ) r # Get the text string is a json 

# json converted into a string dictionary object dic 
dict_json = json.loads (json_response) 
Print (type (dict_json)) 

# json converted into a string dictionary 
str_json = json.dumps( dict_json )
print(type(str_json))

# Dictionary converted into json into the local file 
with Open ( ' ./a.txt ' , ' w ' ) AS f: 
    # settings are not converted to ascii json string first indent 
    f.write (json.dumps (dict_json, ensure_ascii False =, indent = 2 ))

 

 

reference:

https://www.cnblogs.com/niuu/p/10106897.html

https://www.cnblogs.com/Lin-Yi/p/7640147.html

Guess you like

Origin www.cnblogs.com/sea-stream/p/11204595.html