我有這個代碼JSON解析PHP和顯示內容
這是我的PHP與其他項目的合作問題......
$gas = file_get_contents('http://api.mygasfeed.com/stations/loadbygeo/47.9494949/120.23423432/reg|mid|pre|diesel/'. $api . '.json?callback=?');
$json_output = json_decode(utf8_decode($gas));
$location= $json_output->geoLocation->city_id;
這是JSON結果
?({"status":{"error":"NO","code":200,"description":"none","message":"Request ok"},"geoLocation":{"city_id":"13123","city_long":"Hulunber","region_short":"Nei Mongol","region_long":"Nei Mongol","country_long":"China","country_id":"49","region_id":"6010"},"stations":[]})
此代碼返回空白結果。
這不是JSON。這是JSONP。解碼前需要解開函數調用。 – mario
你能澄清一下嗎?該URL不使用jsonp –
@DavidMorin:是的,它的確如此。試試'?callback ='而不是'?callback =?'。 – Ryan