Json file format operation 2

1, converted to a string dictionary (json.dumps)
= {jsongeshi "name": "Yajuan", "Age": "10"} 
Import JSON

with (Open ( "B", "W", encoding = "UTF-. 8")) AS F:
json_new = json.dumps (jsongeshi) # dictionary into a string, write write-only support strings, dictionaries and list format is not supported, so the need to convert
f.write (json_new)


2, string into a dictionary
with (Open ( "B", encoding = "UTF-. 8")) AS f: 
F1 = reached, f.read () # f read file
f2 = json.loads (f1) # string into a dictionary
print (f2)
1, converted to a string dictionary (json.dumps)
= {jsongeshi "name": "Yajuan", "Age": "10"} 
Import JSON

with (Open ( "B", "W", encoding = "UTF-. 8")) AS F:
json_new = json.dumps (jsongeshi) # dictionary into a string, write write-only support strings, dictionaries and list format is not supported, so the need to convert
f.write (json_new)


2, string into a dictionary
with (Open ( "B", encoding = "UTF-. 8")) AS f: 
F1 = reached, f.read () # f read file
f2 = json.loads (f1) # string into a dictionary
print (f2)

Guess you like

Origin www.cnblogs.com/fandonghua/p/11589132.html