我有JSON內容,我需要添加到列表作爲元素列表中的列表。雖然這樣做,'list.append()'方法將JSON內容轉換爲我不想要的字符串。因此,如何將JSON內容作爲元素添加到列表中,以便它仍然是JSON?添加json內容作爲一個元素來列表python
這就是我努力:
def dump_data():
for data in prod_data:
file_name = data['filter'] + '_1.json'
path = check_file_existance(file_name) # If file exists, then this method generates a new file name.
enter_data = list()
enter_data.append(json.dumps(data))
print type(enter_data[0])
with open(path, "ab+") as f:
# json.dump(data, f)
f.write("%s\n" % enter_data)
我們展示你的代碼。 – 2015-02-10 03:19:24
@JohnZwinck:我已經添加了我的代碼。 – 2015-02-10 03:22:12