所以,我必須解析一個php json到javascript中。解析php json到javascript
的代碼看起來是這樣的:
$thumbnails = [];
foreach ($images as $key => $image)
{
$thumbnails[$image->time] = [
'src' => MovieEntity::getImageWithPublicPath(
$movie->id, $image->filename, 130, 0, false
),
'width' => '165px',
'height' => '95px'
];
}
return json_encode($thumbnails, JSON_UNESCAPED_SLASHES);
,其結果是:
{"5":{"src":"google.ro","width":"165px","height":"95px"},"7":
我想借此src
,width
和height
並插入像圖片:
<a href="">
<img src="src of image" width="" height="">
</a>
我需要做什麼? PHP中的這個變量被稱爲$thumbnails
,它返回上面顯示的JSON。
<?php echo $thumbnails ?>
LE:我的解決方案是:
<?= '<script>var json='.$thumbnails.'</script>' ?>
console.log(json);
這將返回在控制檯中JSON。
它不重複。我需要不同的感謝 –