代码如下:
import json
import time
x=1
y=2
z=3
list=[]
def writejson():
global x,y,z
while True:
data = {
"x": x,
"y": y,
"z": z,
}
with open("data.json", 'w') as file_obj:
list.append(data)
json.dump(list, file_obj,indent=2)
print(data)
x += 1
y += 5
z += 10
time.sleep(1)
writejson()
运行结果如下:



