{"code":200,"message":"成功","data":{"access_token":"eyJh} 怎么把access_token对应的值提取
时间: 2023-07-09 21:54:08 浏览: 360
可以使用JSON解析库,比如Python内置的json模块,来解析JSON格式的数据并获取access_token的值。
示例代码如下:
```python
import json
response = '{"code":200,"message":"成功","data":{"access_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2ODY2NDUwMzIsInVzZXJfbmFtZSI6IjAwMzgzMSIsImp0aSI6ImQwZmUyMzgwLTc2MzEtNDA1Ny04NWY5LWM4ZTk1ZWNmMWE5ZSIsImNsaWVudF9pZCI6ImJhc2V1cyIsInNjb3BlIjpbImFsbCJdfQ.lMKp"}}'
# 解析JSON数据
data = json.loads(response)
# 获取access_token的值
access_token = data['data']['access_token']
print(access_token)
```
输出:
```
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2ODY2NDUwMzIsInVzZXJfbmFtZSI6IjAwMzgzMSIsImp0aSI6ImQwZmUyMzgwLTc2MzEtNDA1Ny04NWY5LWM4ZTk1ZWNmMWE5ZSIsImNsaWVudF9pZCI6ImJhc2V1cyIsInNjb3BlIjpbImFsbCJdfQ.lMKp
```
可以看到,我们通过解析JSON数据,成功获取了access_token的值。
阅读全文