chen106106 发表于 2013-1-29 08:46:23

javascript对象转字符串

function objectToString(o){
   
    var parse = function(_o){
   
      var a = [], t;
      
      for(var p in _o){
      
            if(_o.hasOwnProperty(p)){
            
                t = _o;
               
                if(t && typeof t == "object"){
               
                  a= p + ":{ " + arguments.callee(t).join(", ") + "}";
                  
                }
                else {
                  
                  if(typeof t == "string"){
                  
                        a = [ p+ ": \"" + t.toString() + "\"" ];
                  }
                  else{
                        a = [ p+ ": " + t.toString()];
                  }
                  
                }
            }
      }
      
      return a;
      
    }
   
    return "{" + parse(o).join(", ") + "}";
   
}
页: [1]
查看完整版本: javascript对象转字符串