使用jQuery来渲染json [英] Rendering json using jquery

查看:124
本文介绍了使用jQuery来渲染json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个简单的例子,它有一个json数据,我必须解析它并在html中呈现。有人可以建议我一个简单的方法来做到这一点吗?

I need a simple example that has a json data and I have to parse it and render in html. Can someone suggest me a simple way to do this?

推荐答案

你可以从JavaScript中的对象创建一个字符串像这样.. 。

You can create a string from an object in JavaScript like this...

var jsonString = JSON.stringify(myJsonObject);

然后您可以使用该字符串应用到html元素。例如...

Then you can use that string to apply to a html element. For example...

document.getElementById('myDivID').innerText = jsonString;

使用JQuery,您可以使用以下内容更新DIV ...

With JQuery you can update a DIV with the following...

$("#MyDiv").html(jsonString);

这篇关于使用jQuery来渲染json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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