json.load编码问题

书途 215 0

Python报错:

json.decoder.JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1 (char 0)

实际是编码问题,需要decode为utf-8.

res = requests.get(url)
res.encoding="utf-8"
print(res.text)
for each in json.loads(res.text.encode("utf-8")):
    print(each)
(Visited 82 times, 1 visits today)

发表评论 取消回复
表情 图片 链接 代码

分享