我有一个用于操作 JSON 文件的小型 python 程序。我发现当我使用 json.dump() 将操作数据转储回 JSON 文件时,它会更改为<type 'NoneType'>
. 下面数据的原始类型(类型json_data
)是<type 'dict'>
。我将这些 JSON 文档存储在 elasticsearch 中并使用 Kibana4 对其进行可视化。Kibana4 将新添加的整数字段视为字符串。有没有人遇到过这个问题。
import json
fname = "json_data.txt"
with open(fname, 'r+') as f:
json_data = json.load(f)
print(type(json_data))
#Code to add fields to json files.
f.seek(0)
x = json.dump(json_data,f,ensure_ascii=True)
print(type(x))