无法通过获取请求将 JSON 转换为 python 中的字典
Unable to turn JSON to Dictionary in python from get request
我正在尝试将使用 API 从 GET 请求中获得的 json 转换为我可以使用的字典。这是我所做的:
response = requests.get(API)
response_dict = json.loads(response.json())
print(response_dict)
我收到错误:
raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not dict
仔细阅读错误。它表明 response.json()
已经 returns 一个 dict
。无需调用 json.loads
(接受字符串)。
response = requests.get(API)
response_dict = response.json()
就是你所需要的。
我正在尝试将使用 API 从 GET 请求中获得的 json 转换为我可以使用的字典。这是我所做的:
response = requests.get(API)
response_dict = json.loads(response.json())
print(response_dict)
我收到错误:
raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not dict
仔细阅读错误。它表明 response.json()
已经 returns 一个 dict
。无需调用 json.loads
(接受字符串)。
response = requests.get(API)
response_dict = response.json()
就是你所需要的。