python - 我如何从在线文件中读取 JSON 数据?(python)
问题描述
我有一个站点,只有 JSON 数据。我需要用 python 读取这些数据。
所以我需要知道,如何加载在线 JSON。
import json
f = "https://api.npoint.io/7872500d7eef44a03194"
data = json.load(f)
那么这怎么能行呢?然后我如何检查互联网连接错误?
解决方案
带requests
图书馆:
import requests
f = "https://api.npoint.io/7872500d7eef44a03194"
data = requests.get(f).json()
data
输出:
{'sample': 'this is only a sample'}
推荐阅读
- python - Pandas 按序列值的降序重新索引多索引的索引
- reactjs - Cypress 设置默认路径别名
- html - 删除空白 CSS 网格
- c++ - 当我们将变量“u”的数据类型从 long long 更改为 int 时,为什么模幂运算会出错?
- excel - 将带有空白的工作表合并为单个工作表 - VBA
- c - 如何优化 CFD C 代码中的决策
- python - 为什么 zfill 不能处理 python 中的字符串对象?
- python - 如何使用字典在图形上查找最短路线的距离
- swift - 加载应用时,绿色 UITabBarItem 意外变灰
- apache-spark - 使用圆形函数转换 pyspark 数据框列不起作用(pyspark)