您当前的位置:首页 > IT编程 > python
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch |

自学教程:python 读取Unicode编码的json文件转码为汉字utf8json

51自学网 2022-06-08 14:36:34
  python
这篇教程python 读取Unicode编码的json文件转码为汉字utf8json写得很实用,希望能帮到您。
import json

读取json文件
with open("data.json", 'r', encoding='utf-8') as f:
逐行读取
    for jsonstr in f.readlines():

# 转码


    
        we = jsonstr.encode('utf-8').decode('unicode_escape')
        print(we)
with open("1.json","w", encoding='utf-8') as fm:
    fm.write(json.dumps(we ,ensure_ascii=False ) ) 
存为正常汉字的json文件
python把json文件导入mysql数据库
Python json.loads()用法及代码示例
51自学网,即我要自学网,自学EXCEL、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。
京ICP备13026421号-1