-4
我已經經歷了以前的stackoverflow建議,並嘗試了很多方法,但仍然json編碼顯示結果作爲一個字符串不是普通的輸出。 Json一直在正常輸出字符串,我想通過刪除字符串標籤來顯示沒有字符串的結果。Json編碼顯示結果爲字符串
代碼:
$vehiclResult = array(
'Fuel Type' => $VehicleFuel->Fuel_Type . "<br>",
'Fuel Type Code' => $VehicleFuel->Fuel_Type_Code . "<br>",
'Fuel Type Code' => $VehicleFuel->Fuel_Type_Code . "<br>",
'ECE_Unit' => $VehicleFuel->ECE_Unit . "<br>",
'ECE_In'=> $VehicleFuel->ECE_In . "<br>",
'ECE_Out' => $VehicleFuel->ECE_Out . "<br>",
'ECE_All' => $VehicleFuel->ECE_All . "<br>",
'ECE_CO2' => $VehicleFuel->ECE_CO2 . "<br>"
);
$result = array(
'vehicle' => $vehiclResult
);
echo json_encode($result);
die();
}
輸出:
{"vehicle":{"Emission Class":"EU5
","Emission Badge":"4
","Car Tax":"146
","Tax Type":"D
","0":"Vehicle Fuel:
","Fuel Type":"Super
","Fuel Type Code":"1
","ECE_Unit":"l\/100km
","ECE_In":"9.2
","ECE_Out":"5.7
","ECE_All":"7
","ECE_CO2":"163
"}}
** json是字符串**你在什麼地方期待?什麼與中斷標籤? – Steve
什麼是「普通輸出」?按照RTFM你知道'json_encode()'返回字符串,所以一切都很好。 –
換行符來自字符串中'
'標籤的結果。如果你看看這個輸出的簡單源代碼,你會發現,這是非常好的JSON。 – Sirko