我有这个输出,我只想尝试在变量中回显令牌或存储令牌
object(stdClass)#1 (9) {
["loggedIn"]=> bool(true)
["token"]=> string(32) "xe5b6bHPPo-_nAvB78NfTpopq9e44bYb"
["secret"]=> string(20) "icCPoDvcf1Vvm2i7-6GM"
["expirationTimestamp"]=> string(24) "2016-11-26T16:32:29.728Z"
["type"]=> string(4) "USER"
["data"]=> object(stdClass)#2 (17)}
这是我的代码:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://security.voluum.com/login");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
$headers = array();
$headers[] = "Authorization: Basic plFubTHhcl93MzA4QHJJkQ9vqmNvwTpMNYYUIz5kcm9s";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
var_dump(json_decode($result));
var_dump(json_decode($result, true));
echo $result->token;
curl_close ($ch);
?>
上面的代码是否正确?如何从输出中提取单个数据?请帮帮我
答案 0 :(得分:3)
$res_decoded = json_decode($result);
echo $res_decoded->token;