我应该如何使用Python解析JSON API响应?我目前有以下代码:
import urllib.request
import json
url = 'https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty'
def response(url):
with urllib.request.urlopen(url) as response:
return response.read()
res = response(url)
print(json.loads(res))
我遇到了这个错误: TypeError: JSON对象必须是 str 类型,而不是 'bytes'
对于处理json接口,有什么符合python规范的方法吗?
pip install requests
- gtlambertJSON对象必须是str类型,而不是'bytes'
... 你有什么想法吗? - pookie