json中主要是方法的使用,“dump”'\"dumps"和“load”以及"loads",具体代码如下:
import json # dic = {'name':'leo','age':'18','sex':'male'} # date = json.dumps(dic) # f = open('jason_text','w') # f.write(date) # f.close() dic_2 ={'hobbie':'basketball'} f = open('jason_text2', 'w') json.dump(dic_2,f) f.close()
import json # f = open('jason_text', 'r') # date = f.read() # date = json.loads(date) # print(date['name']) f = open('jason_text2','r') date = json.load(f) print(date['hobbie'])