Python 实现 csv文件转换成json文件
参考链接https://blog.csdn.net/admans/article/details/102988114
# -*- coding:utf-8 -*-
# csv转换成json
import csv
import json
file_path = "C:\\Users\\Surface\\Desktop\\college\\college_data.csv"
csvfile = open(file_path, 'r', encoding='utf-8') # 指定encodeing='utf-8'中文防止乱码
jsonfile = open('college_data.json', 'w', encoding='utf-8')
fieldnames = ("code", "name") # 指定列名
reader = csv.DictReader(csvfile, fieldnames)
out = json.dumps([row for row in reader], ensure_ascii=False)
# 指定ensure_ascii=False 为了不让中文显示为ascii字符码
jsonfile.write(out)