解析json数据,以chrome扩展名的形式查看 [英] Parse json data to view as an image in chrome extension

查看:194
本文介绍了解析json数据,以chrome扩展名的形式查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有图像和文本作为json数据.

I have images and texts as json data.

"imageCollection": {
"Name": "Anna",
"imageUrl":"https://xxx/xxx/img.jpg?t=5657565",
},

我使用这种方法将json数据解析为图片,但是我想在弹出窗口中并排添加图片和文本.

I used this approach to parse json data into image but I want to append image and text side by side in my popup window.

document.getElementById("img").src=                    
jsonData.imageCollection.logo; 

我之前写过的将json数据解析为html的内容

what i wrote before to parse json data to html

 document.getElementById("host").innerHTML= 
 jsonData.imageCollection.Name

我应该如何将这两种方法合而为一?有什么建议吗? 我的popup.html

how should i merge this two method in one to append together? any Suggestion please? my popup.html

<div id="host">
 <image id="img"></image>
</div>

推荐答案

尝试使用图片的src属性

Try using src property of image

document.getElementById("IMAGE_TAG_ID").src = jsonData.imageCollection.imageUrl;

将IMAGE_TAG_ID替换为您的图像标签ID.

replace IMAGE_TAG_ID to your image tag id.

这篇关于解析json数据,以chrome扩展名的形式查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆