2017-11-25 115 views
0

我用盡了一切,但仍然無法從以下網址獲得JSON內容得到JSON內容:http://onderbrekingen.infrax.be/onderbrekingen/Home/GetOnderbrekingen無法從遠程URL

這是我最新的PHP:

$url = 'http://onderbrekingen.infrax.be/onderbrekingen/Home/GetOnderbrekingen'; 
$curlSession = curl_init(); 
curl_setopt($curlSession, CURLOPT_URL, 'http://onderbrekingen.infrax.be/onderbrekingen/Home/GetOnderbrekingen'); 
curl_setopt($curlSession, CURLOPT_BINARYTRANSFER, true); 
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curlSession, $jsonData = json_decode(curl_exec($curlSession)); 
curl_close($curlSession); 

switch (json_last_error()) { 
case JSON_ERROR_DEPTH: 
    echo 'json_decode() - Maximum stack depth exceeded'; 
break; 
case JSON_ERROR_STATE_MISMATCH: 
    echo 'json_decode() - Underflow or the modes mismatch'; 
break; 
case JSON_ERROR_CTRL_CHAR: 
    echo 'json_decode() - Unexpected control character found'; 
break; 
case JSON_ERROR_SYNTAX: 
    echo 'json_decode() - Syntax error, malformed JSON'; 
break; 
case JSON_ERROR_UTF8: 
    echo 'json_decode() - Malformed UTF-8 characters, possibly incorrectly encoded'; 
break; 
default: 
    echo 'json_decode() - Unknown error'; 
break; 
case JSON_ERROR_NONE: 
    print '<b>JSON var_dump:</b>'; 
    print '</br></br>'; 
    var_dump($jsonData); 
    print '</br></br><hr></br>'; 
break; 
} 

print '<b>echo content:</b>'; 
print '</br>'; 
echo stream_get_contents(fopen($url, "r")); 

我已經也試過用file_get_contents(),也不行。 var_dump每次都會返回NULLstream_get_contents也似乎不會返回原始的JSON內容。

Grtz, phyck

+1

告訴我們的輸出,而不是隻是 「它不工作」會很有幫助 – KayakinKoder

+1

爲什麼:curl_setopt($ curlSession,$ jsonData = json_decode(curl_exec($ curlSession)); –

+0

只寫: $ jsonData = json_decode(curl_exec($ curlSession)); –

回答

0

更換

curl_setopt($curlSession, $jsonData = json_decode(curl_exec($curlSession)); 

$jsonData = json_decode(curl_exec($curlSession)); 
curl_setopt($curlSession, $jsonData,true); 

它工作得很好,當我測試

//output 
{"Onderbrekingen":[{"Id":"5f303a78-6bcb-e711-80d7-005056b663fa","Cabinenummer":"097LTF","Onderbrekingstype":"Storing","Discipline":"Elektriciteit","Postcode":" ","Gemeente":" ","BeginDatum":"\/Date(1510873200000)\/","EindDatum":null,"BeginUur":"08:46","EindUur":null,"Latitude":0,"Longitude":0,"GeimpacteerdeStraten":[],"GeimpacteerdKlantAantal":"101 - 500","ExtraBeschrijving":null,"DnbCode":null,"Scada":true,"InterneOpmerking":"Aangemaakt vanuit SCADA","IsRedLine":true,"ValidationErrors":null,"IsValid":true,"IsDirty":true,"Error":""}],"ScadaSync":"19:16"}<b>JSON var_dump:</b></br></br>int(1) 


0

@hazelcodes:謝謝,但它仍然不能在我的網絡服務器上工作。

仍然得到同樣的輸出:

JSON的var_dump:

NULL

回聲內容: