简体   繁体   English

Python json库无法解析有效的json字符串?

[英]Python json library not parsing valid json string?

I am trying to parse json obtained from this api call: https://poloniex.com/public?command=returnTicker 我正在尝试解析从此api调用获得的json: https : //poloniex.com/public? command =returnTicker

But when I run the commands: 但是当我运行命令时:

    print site_name
    site = urllib2.Request(site_name)

    response=urllib2.urlopen(site_name) 

    print response.read()

    t= json.loads(response.read())

I get: 我得到:

https://poloniex.com/public?command=returnTicker
{"BTC_BCN":  ... (rest of json response)
ValueError: No JSON object could be decoded

I have validated the resulting json object using www.jsonlint.com and it is valid. 我已经使用www.jsonlint.com验证了生成的json对象,它是有效的。 What am I doing wrong? 我究竟做错了什么?

if you print response.read() , then the next time you try to read from it you'll get an empty string. 如果您print response.read() ,则下次尝试从中read时,您将获得一个空字符串。

Empty string is not a valid json string. 空字符串不是有效的json字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM