尝试在python中加载和使用json时出现许多错误

时间:2018-10-07 17:50:31

标签: json python-3.x api python-3.7

我尝试使用.read()和.decode(“ utf-8”)只是不断出现这样的错误,例如'TypeError:只能将str(而不是“ dict”)连接到str'

from requests import get
import json

url = 'http://taco-randomizer.herokuapp.com/random/?full-taco=true'
requested_taco = get(url)
requested_taco_data = json.loads(requested_taco.read())
title = requested_taco_data['name']

在此先感谢所有能够帮助我弄清楚如何使json成为python中的字典的人。

1 个答案:

答案 0 :(得分:1)

“请求”中没有compile group: 'org.openjfx', name: 'javafx-base', version: '11', classifier: 'linux' compile group: 'org.openjfx', name: 'javafx-graphics', version: '11', classifier: 'linux' ,您应该像这样使用response.read()

response.json()

它将输出:

taco = requested_taco.json()
print(taco['name'])

不需要json库。