求一个把JSON数据解析并在JSP上显示的代码

数据是这样的:{"status":"1","error":null,"appName":"xmt_dbg","appCompany":"TRS_Project4","ap... 数据是这样的:

{"status":"1","error":null,"appName":"xmt_dbg","appCompany":"TRS_Project4","appList":
[{"id":2720,"text":"中文","isVirtual":0,"expression":null,"isSons":1,"virtual":false,"code":";1;"},

{"id":2791,"text":"Español","isVirtual":0,"expression":null,"isSons":1,"virtual":false,"code":";4;"},

{"id":2710,"text":"Frangais","isVirtual":0,"expression":null,"isSons":1,"virtual":false,"code":";3;"},

{"id":2715,"text":"English","isVirtual":0,"expression":null,"isSons":1,"virtual":false,"code":";2;"},

{"id":2795,"text":"português","isVirtual":0,"expression":null,"isSons":1,"virtual":false,"code":";7;"},
{"id":2767,"text":"Русский язык","isVirtual":0,"expression":null,"isSons":1,"virtual":false,"code":";5;"},
{"id":2713,"text":" عربى","isVirtual":0,"expression":null,"isSons":1,"virtual":false,"code":";6;"},
{"id":4818,"text":"党政企客户端","isVirtual":0,"expression":null,"isSons":1,"virtual":false,"code":";DZKHDFL;"},
{"id":4819,"text":"新华通","isVirtual":0,"expression":null,"isSons":1,"virtual":false,"code":";XHTFL;"}]}
求解析完在JSP界面上显示结果,求大神指导
展开
 我来答
o卡卡西老师o
推荐于2016-04-24 · 超过50用户采纳过TA的回答
知道小有建树答主
回答量:69
采纳率:100%
帮助的人:80.1万
展开全部
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
#div1 div,span{color:red;}
</style>
<script type="text/javascript" src="../assets/js/jquery.min.js"></script>
    <script type="text/javascript">
    $(function(){
     var data={"status":"1","error":null,"appName":"xmt_dbg","appCompany":"TRS_Project4","appList":
     [{"id":2720,"text":"中文","isVirtual":0,"expression":null,"isSons":1,"virtual":false,"code":";1;"},

      {"id":2791,"text":"Espa&#241;ol","isVirtual":0,"expression":null,"isSons":1,"virtual":false,"code":";4;"},

      {"id":2710,"text":"Frangais","isVirtual":0,"expression":null,"isSons":1,"virtual":false,"code":";3;"},

      {"id":2715,"text":"English","isVirtual":0,"expression":null,"isSons":1,"virtual":false,"code":";2;"},

      {"id":2795,"text":"português","isVirtual":0,"expression":null,"isSons":1,"virtual":false,"code":";7;"},
      {"id":2767,"text":"Русский язык","isVirtual":0,"expression":null,"isSons":1,"virtual":false,"code":";5;"},
      {"id":2713,"text":" &#1593;&#1585;&#1576;&#1609;","isVirtual":0,"expression":null,"isSons":1,"virtual":false,"code":";6;"},
      {"id":4818,"text":"党政企客户端","isVirtual":0,"expression":null,"isSons":1,"virtual":false,"code":";DZKHDFL;"},
      {"id":4819,"text":"新华通","isVirtual":0,"expression":null,"isSons":1,"virtual":false,"code":";XHTFL;"}]};
    
     $("div").html(JSON.stringify(data).toString());
    });
</script>
</head>
<body>
<div></div>
</body>
</html>

展示如下:

不要谢我,我叫雷哄


另外给你说下js本身对json的处理函数吧,如下:

JSON.parse(你的json类型的字符串);

parse用于从一个字符串中解析出json对象,如

var str = '{"name":"huangxiaojian","age":"23"}'

结果:

JSON.parse(str)

Object

age: "23"

name: "huangxiaojian"

__proto__: Object



注意:单引号写在{}外,每个属性名都必须用双引号,否则会抛出异常。

JSON.stringify(你的json对象);

stringify()用于从一个对象解析出字符串,如

var
a = {a:1,b:2}

结果:

JSON.stringify(a)

"{"a":1,"b":2}"

更多追问追答
追问
兄弟谢谢你,请问如果把解析完的对象放在表格里输出怎么弄,我是新手,求代码和讲解,谢谢
追答

这个方便,你百度一下dtgrid,他可以直接接受data格式的对象,这个表格非常的强大,是一种js插件。我给你放到附件里面了。里面查看页面的路径是jquery.dtGrid.v1.1.9.Java.Web.App.zip\WebContent\dtGrid\doc\i18n\zh-cn ,你自己看看吧。他有个参数叫data:你的json对象

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式