【发布时间】:2017-10-20 07:49:18
【问题描述】:
所以,我必须将一个 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。
【问题讨论】:
-
它不重复。我需要一些不同的东西谢谢
标签: javascript php jquery json yii