【发布时间】:2017-11-29 17:51:47
【问题描述】:
代码:
with open(read_json,'r',encoding='utf-8') as json_file:
json_data = json.load(json_file)
print(json_data)
with open(write_csv,'w',encoding='utf-8') as csv_file:
headers, items = parse_json(json_data,query_type)
# i is to be iterated to get all maxResults = 50.
writer = csv.writer(csv_file)
writer.writerow(headers)
for row in items:
writer.writerow(row)
CSV 文件:
我的 CSV 文件中有奇怪的字符,不确定发生了什么。
【问题讨论】:
-
这是 UTF-8 多字节字符显示为错误的代码页,如果在 Windows 上可能是 cp1252。您是在 Excel 还是记事本中查看 CSV?使用
utf-8-sig作为编码应该可以解决这个问题。 -
@MarkTolonen 我正在使用 excel
-
@MarkTolonen 非常感谢你,你能解释一下出了什么问题吗,我是编程新手。