php - 如何从数组php中只获取一个元素
问题描述
我有这个 JSON 数组数据
{"accessToken":"eyJhbGciOiJSUzUxMiJ9.e","refreshToken":"QErx0bUxyx6wxFj5AXcAh21UuyO8ad/ULIaGlP3LU2lmXGnx0twbYdM+nJyfwAcK9Av50uZ3fSZ/2nhJwIi+bA==","expiresIn":"2021-11-11T10:20:33Z","issuedAt":"2021-11-11T10:05:33Z","tokenType":"Bearer"}
如何accessToken
从数组中仅获取对象。IEyJhbGciOiJSUzUxMiJ9.e
这就是我尝试过的方式
$response = curl_exec($curl);
curl_close($curl);
$token = $response['accessToken'];
echo $token;
但我得到这个错误
Warning: Illegal string offset 'accessToken'
解决方案
$response = curl_exec($curl);
curl_close($curl);
$data = json_decode($response, true);
echo $data['accessToken'];
推荐阅读
- mysql - Mysql 过程语法更改为 Firebird 过程语法
- jenkins - Jenkins Blue Ocean 重试限时步骤,最多 n 次
- java - Selenium WebDriver:随机单击一行按钮
- javascript - 从axios回调后如何清除字段?
- android - getFilter() 在 RecyclerView 适配器中无法正常工作?
- airflow - 如何运行 Airflow DAG 特定次数?
- python-3.4 - ord() 函数或带有 Z3 Solver 的字符串的 ASCII 字符代码
- flutter - 颤动行mainAxisAlignment spaceBetween不工作
- robotframework - 如何在机器人框架的 FOR 循环中使用 if/else 条件
- python-3.x - 如何将主机 IP 地址分配给我的 POSTGRESQL 数据库