JsonObjectToString

<script type="text/javascript">// <![CDATA[
JsonObjectToString=function(o) {
    var arr=[];
    var fmt = function(s) { 
            if (typeof s == 'object' && s != null ) return JsonObjectToString(s); 
            return /^(string|number)$/.test(typeof s) ? "'" + s + "'" : s; 
    };
    
    if(o instanceof Array){
        for (var i in o){
                arr.push(fmt(o[i]));
        }
        return '[' + arr.join(',') + ']';
            
    }
    else{
        for (var i in o){
                arr.push("'" + i + "':" + fmt(o[i]));
        }
        return '{' + arr.join(',') + '}'; 
    }
};
// ]]></script>
posted @ 2012-08-29 17:05  南斗兄弟  阅读(507)  评论(0)    收藏  举报