我已经完成了之前的stackoverflow建议并尝试了很多方法,但仍然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
"}}
答案 0 :(得分:-1)
如果您希望在html页面中使用这些值
使用javascript http://api.jquery.com/jquery.parsejson/
从字符串中解析值。
var response = $.parseJSON(data);
console.log(response);