What is this Data Type (Get Request) bit.ly oauth2

2019-09-20 17:45发布

{ "status_code": 200, "status_txt": "OK", "data": { "long_url": "http:\/\/google.com\/", "url": "http:\/\/bit.ly\/17A2GVj", "hash": "17A2GVj", "global_hash": "3j4ir4", "new_hash": 0 } } 

I get something like this after i do a

$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => 'https://api-ssl.bitly.com/v3/shorten?access_token=xxx&longUrl=http%3A%2F%2Fgoogle.com%2F',
    CURLOPT_USERAGENT => 'Mozilla/4.0'
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);

echo $resp;

How do i read "hash"

标签: php html json curl
1条回答
欢心
2楼-- · 2019-09-20 18:42
$respObj = json_decode($resp);
echo $respObj->data->hash;

json_decode, by default, returns an instance of stdClass. Access stdClass' members with ->.

查看更多
登录 后发表回答