`

javascript对象转字符串

阅读更多
function objectToString(o){
   
    var parse = function(_o){
   
        var a = [], t;
       
        for(var p in _o){
       
            if(_o.hasOwnProperty(p)){
           
                t = _o[p];
               
                if(t && typeof t == "object"){
               
                    a[a.length]= p + ":{ " + arguments.callee(t).join(", ") + "}";
                   
                }
                else {
                   
                    if(typeof t == "string"){
                   
                        a[a.length] = [ p+ ": \"" + t.toString() + "\"" ];
                    }
                    else{
                        a[a.length] = [ p+ ": " + t.toString()];
                    }
                   
                }
            }
        }
       
        return a;
       
    }
   
    return "{" + parse(o).join(", ") + "}";
   
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics