1. 导入必要的库,如`requests`。
2. 使用`requests.get()`方法发送HTTP GET请求到目标URL。
3. 调用`response.json()`方法将返回的JSON内容解析为Python字典对象。
```python
import requests
定义要获取的JSON数据的URL
url = 'https://api.example.com/data.json'
发送GET请求
response = requests.get(url)
检查请求是否成功
if response.status_code == 200:
解析JSON数据
data = response.json()
打印解析后的数据
print('Name:', data['name'])
print('Age:', data['age'])
print('Emails:', data['emails'])
else:
print('Failed to retrieve data:', response.status_code)
请确保将`url`变量替换为您要获取的JSON数据的实际网址。如果需要处理登录认证或其他特殊请求,可能需要对请求进行额外的配置。