码迷,mamicode.com
首页 > Web开发 > 详细

输出json对象

时间:2015-06-17 11:23:59      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:

 1 <html>
 2 <head>
 3   <script src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
 4 </head>
 5 <body>
 6 <script>
 7 var object1 = {
 8   apple: 0,
 9   banana: {weight: 52, price: 100},
10   cherry: 97
11 };
12 var printObj = typeof JSON != undefined ? JSON.stringify : function(obj){
13     var arr = [];
14     $.each(obj,function(key,val){
15         var next = key + :;
16         next += $.isPlainObject(val) ? printObj(val) : val;
17         arr.push(next);
18     });
19     return {  + arr +  };
20 }
21 alert(printObj(object1));
22 </script>
23 </body>
24 </html>

 

输出json对象

标签:

原文地址:http://www.cnblogs.com/k11590823/p/4582601.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!