【发布时间】:2016-05-09 07:08:03
【问题描述】:
如何使用 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'
pythonic 处理 json api 的方式是什么?
【问题讨论】:
标签: python json python-3.x api