Python and json

储存数据到json:
import json
numbers = [‘123423’,‘234234’,‘234234’]
filename = ‘/Users/macbook/Desktop/4.json’

with open(filename,‘w’)as f_obj:
json.dump(numbers,f_obj)
读取json中的数据:
import json

filename = ‘/Users/macbook/Desktop/4.json’

with open(filename)as f_obj:
numbers = json.load(f_obj)
print(numbers)

储存输入的字段到json文件中:
import json

filename = ‘/Users/macbook/Desktop/4.json’

username = input(“What is your name”)

with open(filename,‘w’)as f_obj:
json.dump(username,f_obj)
print(“We will remeber your name”+username+",hahahah")

你可能感兴趣的:(Python and json)