首页 > 解决方案 > 我如何从在线文件中读取 JSON 数据?(python)

问题描述

我有一个站点,只有 JSON 数据。我需要用 python 读取这些数据。

所以我需要知道,如何加载在线 JSON。

import json

f = "https://api.npoint.io/7872500d7eef44a03194"

data = json.load(f)

那么这怎么能行呢?然后我如何检查互联网连接错误?

标签: pythonjsonapi

解决方案


requests图书馆:

import requests

f = "https://api.npoint.io/7872500d7eef44a03194"
data = requests.get(f).json()

data

输出:

{'sample': 'this is only a sample'}

推荐阅读