qq_23373117
qq_23373117
2016-04-23 08:06

python json解析出现No JSON object could be decoded的报错

  • windows

源代码:#coding:utf-8
import requests
import re
import json

url="http://www.newrank.cn/public/info/list.js?t=1461063208.68"
user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
headers = { 'User-Agent' : user_agent }
jscontent=requests.get("http://www.newrank.cn/public/info/list.js?t=1461063208.68",headers=headers).content
jsdict=json.loads(jscontent)

错误信息:Traceback (most recent call last):
File "D:/Python/JetBrains PyCharm 5.0.4/PyCharm 5.0.4/Myproject/test1/test2.py", line 10, in
jsdict=json.loads(jscontent)
File "D:\Python\lib\json__init__.py", line 339, in loads
return _default_decoder.decode(s)
File "D:\Python\lib\json\decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "D:\Python\lib\json\decoder.py", line 382, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

是因为json的bom头问题吗,我也尝试过一些网上的去除bom头的办法,不过都不管用,还望指点,非常头疼,谢谢!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答