我不确定问题的具体术语,所以让我描述一下确切的问题本身:
test.csv
:
foo,char
"bar","µ"
test.py
:
#!/usr/bin/env python3
import csv
import json
with open('test.csv', mode='r') as file:
reader = csv.DictReader(file)
for row in reader:
print(json.dumps(row))
预期输出:
{"foo": "bar", "char": "µ"}
实际输出:
{"foo": "bar", "char": "\u00b5"}
我尝试将encoding='utf-8'
添加到open()
,但不会更改输出。