python - 从请求中获取 JSON 参数,我得到 : 'method' object is not subscriptable

标签 python json python-requests

我正在尝试从加载了请求的 JSON 字符串中获取参数。

我想我尝试了我能想到的任何组合。

非常感谢任何提示。

我的代码是这样的:

r = requests.get(url, headers=headers)
json_string = r.json
status = json.dumps(json_string['httpStatusCode'])

我得到了

'method' object is not subscriptable

最佳答案

您收到的错误是因为您将“方法”对象分配给 json_string。
因为在 python 中,“方法”对象不可订阅。

要获得 JSON 响应,您必须这样做

json_string = r.json()

关于python - 从请求中获取 JSON 参数,我得到 : 'method' object is not subscriptable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46095622/

相关文章:

python - 在 ipython/jupyter notebook 中注册内核 - kernel.json

android - 在 Android 中发布 JSON 并检索响应

python - 如何指定python请求http put body?

Python 值错误 : Invalid header name b':authority

python - 将数据帧转换为 JSON,并使用 1 个公共(public)值列作为数组字段

python requests 模块 - 将键设置为 null

c++ - Boost.Python 包装层次结构避免菱形继承

c++ - 为什么python 3.2的Python.h必须和Qt4一起先包含进来

python - 为什么同一对象的不同方法具有相同的 `id` ?

json - 使用 F# 解析 JSON(不是序列化)