1
我想解碼一個json對象,以便我可以從中獲取圖像url。通常這工作正常,但不知何故,下面的代碼不適合我。從json對象獲取圖像url無法正常工作
$partimages1 = $prods['images'];
$partsimg1 = json_decode($partsimages1);
if($partsimg1->image_intro != ''){
$productimages = '<img class="kw-prodimage-img" src="cms/'.$partsimg1->image_intro.'" alt="Product 1" title="Product 1" />';
}else{
$productimages = '<img class="kw-prodimage-img" src="images/backgroundheader.jpg" alt="Product 1" title="Product 1" />';
}
上述代碼在對象內部存在圖像時總是返回backgroundheader.jpg。
當我回聲$ partimages1這就是結果:
{"image_intro":"images\/Afbeeldingen\/lassen2.jpg","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"","float_fulltext":"","image_fulltext_alt":"","image_fulltext_caption":""}
到底哪裏出問題了?
調高你的錯誤報告。你會立即看到這個問題。 'error_reporting = E_ALL' – Phil