嗨,我正在尝试使用 Curl 和 PHP 使用以下代码从 url 从 JSON 文件中获取数据:
<?php
// Initiate curl
$url = "https://panel.virtualcenter360.es/home/api/getdatasample?dateIni=1376524800&dateEnd=1381795200";
$ch = curl_init($url);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
$result=curl_exec($ch);
$res = iconv('UTF-8', 'UTF-8//IGNORE', utf8_encode($result));
var_dump(json_decode($res, true));
switch (json_last_error()) {
case JSON_ERROR_NONE:
echo ' - No errors';
break;
case JSON_ERROR_DEPTH:
echo ' - Maximum stack depth exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
echo ' - Underflow or the modes mismatch';
break;
case JSON_ERROR_CTRL_CHAR:
echo ' - Unexpected control character found';
break;
case JSON_ERROR_SYNTAX:
echo ' - Syntax error, malformed JSON';
break;
case JSON_ERROR_UTF8:
echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
break;
default:
echo ' - Unknown error';
break;
}
curl_close($ch);
?>
我收到无错误消息,但结果为 NULL。你认为这可能是什么问题?
也许我需要从 Curl 配置一些参数?
谢谢!