所以即時嘗試使用CURL獲得JSON返回,但是我不斷得到一個NULL值。PHP JSON捲曲問題
POST變量{mgf = userData; apiKey = 123455678qwertyui}
<?
$data = json_encode(array(
"mgf" => "userData",
"apiKey" => "123455678qwertyui"
));
$data_string = json_encode($data);
$ch = curl_init('http://www.mgf.ltd.uk/software-test/api.php');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
$result = json_decode($result);
var_dump($result);
?>
瓦爾傾倒之前的原始結果對它進行解碼,因爲它可能包含無效字符,最終在解碼後爲空。 – Tacsiazuma