2 qq 23373117 qq_23373117 于 2016.04.23 16:06 提问

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

源代码:#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个回答

CSDNXIAOS
CSDNXIAOS   2016.04.23 16:12

Could not write JSON: java.lang.Integer cannot be cast to java.math.BigInteger

使用Number解决

......
答案就在这里:Could not write JSON: java.lang.Integer cannot be cast to java.math.BigInteger
----------------------Hi,地球人,我是问答机器人小S,上面的内容就是我狂拽酷炫叼炸天的答案,除了赞同,你还有别的选择吗?

oyljerry
oyljerry   Ds   Rxr 2016.04.23 21:33

你得到的content先看看是什么数据 看上去不是json数据

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!