python解析json数据

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jin_tmac/article/details/79962394

在用json.load()读取json数据时,

with open(r'E:\XX项目\xxx\{}'.format(file_name1[fi]), 'r') as f:
    data1 = json.load(f)

报如下错误:
UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xac
python无法把一些字符Decode成utf8

解决方法是

with open(r'E:\XX项目\xxx\{}'.format(file_name1[fi]), 'r', encoding='utf-8') as f:
    data1 = json.load(f)

json load dump总结:

json.dumps : dict转成str json.dump是将python数据保存成json

json.loads:str转成dict json.load是读取json数据

猜你喜欢

转载自blog.csdn.net/jin_tmac/article/details/79962394
今日推荐