js --> obj2str

来源:互联网 发布:我的体育老师卫视网络 编辑:程序博客网 时间:2024/06/08 07:14
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();
}
原创粉丝点击