【发布时间】:2018-03-19 23:23:33
【问题描述】:
我想从 json 中回显“Active”这个词。
“状态”:“活动”
PHP/CURL:
$ch = curl_init("http://ip:port/player_api.php?username=$username&password=$password");
$headers = array();
$headers[] = "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:51.0) Gecko/20100101 Firefox/51.0";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:51.0) Gecko/20100101 Firefox/51.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$result = curl_exec($ch);
// Now i need to decode the json
json:
{"user_info":{"username":"test","password":"test","message":"","auth":1,"status":"Active","exp_date":null,"is_trial":"0","active_cons":"0","created_at":"000","max_connections":"1","allowed_output_formats":["m3u8","ts","rtmp"]},"server_info":{"url":"111.111.111","port":"80","rtmp_port":"80","timezone":"test","time_now":"2018-03-20"}}
【问题讨论】:
-
@ObsidianAge 不,我知道如何用 php 解码。但我需要知道如何用 curl 解码
-
您将 JSON 存储为 PHP 变量
$result;您需要使用 PHP 对其进行解码。为什么你认为你需要用 CURL 本身来解码它? CURL 不知道返回数据的结构。您绝对需要使用 PHP 解码您的 JSON,并且该链接会告诉您确切的操作方法。