首页 > Web开发 > 详细

js json转字符串

时间:2015-05-19 18:47:28      阅读:244      评论:0      收藏:0      [点我收藏+]
function obj2str(o){
       var r = [];
       if(typeof o == "string" || o == null) {
         return o;
       }
       if(typeof o == "object"){
         if(!o.sort){
           r[0]="{"
           for(var i in o){
             r[r.length]=i;
             r[r.length]=":";
             r[r.length]=obj2str(o[i]);
             r[r.length]=",";
           }
           r[r.length-1]="}"
         }else{
           r[0]="["
           for(var i =0;i<o.length;i++){
             r[r.length]=obj2str(o[i]);
             r[r.length]=",";
           }
           r[r.length-1]="]"
         }
         return r.join("");
       }
       return o.toString();
    }

 

js json转字符串

原文:http://www.cnblogs.com/hzm112567/p/4515162.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!