我想解析来自Python中HTTP请求的JSON响应。但我收到以下异常:从HTTP响应解析Json字符串
ValueError: No JSON object could be decoded
Python代码:
profile = webdriver.FirefoxProfile()
profile.set_preference('network.http.phishy-userpass-length', 255)
browser = webdriver.Firefox(firefox_profile=profile)
browser.get("https://"+username+":"+password+"@"+url)
htmltext= str(browser.page_source)
html=soup(htmltext)
jsondata= str(html.find('pre')).strip('</pre>')
data=json.loads(jsondata)
print data['entries']
JSON响应:
{
"count":1,
"entries":
[
{
"id":15862,
"application":loginAudit,
"user":[email protected],
"time":"2014-10-30T02:08:14.103-04:00",
"values":
{
"\/loginAudit\/login\/no-error\/user":"[email protected]"
}
}
]
}
我没有看到你初始化jsondata。 – 2014-11-03 10:11:39
'jsondata'从哪里来? – 2014-11-03 10:12:36
请注意,您在此处发布的JSON无效; 'application'和'user'值没有引号。你可以通过使用linter来测试某些东西是否是有效的JSON。 JSONLint.com提供一个在线。 – 2014-11-03 10:14:42