# -*- coding:utf-8 -*-
# csv转换成json
import csv
import jsonfile_path = "district.csv"
# 指定encodeing='utf-8'中文防止乱码
csvfile = open(file_path,'r', encoding='utf-8')
jsonfile = open('district.json', 'w',encoding='utf-8')# 指定列名
fieldnames = ("code", "name")reader = csv.DictReader( csvfile, fieldnames)
# 指定ensure_ascii=False 为了不让中文显示为ascii字符码
out = json.dumps( [ row for row in reader ] ,ensure_ascii=False)jsonfile.write(out)