json.decoder.JSONDecodeError: Unexpected UTF-8 BOM ...
文章推薦指數: 80 %
Python3解析json文件时报错:json.decoder.JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1.
首页
新闻
博问
专区
闪存
班级
我的博客
我的园子
账号设置
简洁模式...
退出登录
注册
登录
那时的吻狠陶醉
Python3解析json文件时报错:json.decoder.JSONDecodeError:UnexpectedUTF-8BOM(decodeusingutf-8-sig):line1column1
如你之前的json文件为:girl.json
解决方案:将该json文件从之前的UTF-8转换为ANSI编码。
或者UTF-8无BOM格式编码的。
然后json.loads就可以识别,并转换为python对象了
实例:json文件
{
"employees":[
{"firstName":"Bill","lastName":"Gates"},
{"firstName":"George","lastName":"Bush"},
{"firstName":"Thomas","lastName":"Carter"},
{"姓":"付","名":"航"}
]
}
python代码:
#!usr/bin/envpython
#-*-coding:utf-8-*-
importjson
f=open("girl.json",encoding='utf-8')
s=json.load(f)
print(s)
参考链接:https://www.crifan.com/fixed_problem_for_python_valueerror_no_json_object_could_be_decoded/
感谢
posted@
2018-01-2510:55
那时的吻狠陶醉
阅读(5204)
评论(0)
编辑
收藏
举报
刷新评论刷新页面返回顶部
Copyright©2022那时的吻狠陶醉
Poweredby.NET6onKubernetes
延伸文章資訊
- 1line 1 column 1 (char 0) ---While Tuning gpt2.finetune ...
問題描述JSONDecodeError: Unexpected UTF‑8 BOM (decode using utf‑8‑sig): line 1 column 1 (char 0) ‑‑‑W...
- 2Python load json file with UTF-8 BOM header - Stack Overflow
You can open with codecs : import json import codecs json.load(codecs.open('sample.json', 'r', 'u...
- 3How to remove BOM from any text/XML file - IBM
- 4Byte order mark - Globalization - Microsoft Learn
- 5Unexpected UTF-8 BOM (decode using utf-8-sig) - 简书
原因分析:text包含BOM字符解决方案:将BOM头去掉. 问题描述: json.loads(text,encoding='utf8') 报Unexpected UTF-8 BOM (decod...