parseJSON()

var oo = '{"gname":"\u5c60\u9f99\u4f20\u8bf4","status":"1","servers":{"29":"\u9b54\u9f99\u4e4b\u5fc3","28":"\u51e4\u821e\u4e5d\u5929","27":"\u77f3\u7834\u5929\u60ca","26":"\u60ca\u5929\u4e00\u5251","25":"\u738b\u8005\u5f52\u6765","24":"\u55dc\u8840\u738b\u57ce","23":"\u5929\u9b54\u795e\u575b","22":"\u75af\u9b54\u4f20\u8bf4","21":"\u5c60\u622e\u5929\u4e0b","20":"\u552f\u6211\u72ec\u5c0a","19":"\u9738\u6c14\u7eb5\u6a2a","18":"\u88c2\u5929\u7834\u5730","17":"\u5929\u9f99\u6f5c\u5f71","16":"\u865a\u65e0\u5e7b\u6d77","15":"\u51e4\u51f0\u795e\u821e","14":"\u66dc\u65e5\u5f00\u5929","13":"\u7384\u5929\u90aa\u5e1d","12":"\u5e1d\u6068\u5929\u8bdb","11":"\u864e\u9b44\u5929\u6676","10":"\u5341\u65b9\u4ff1\u706d","9":"\u4e07\u4e8b\u5982\u610f","8":"\u6218\u65e0\u4e0d\u80dc","7":"\u9738\u738b\u522b\u59ec","6":"\u798f\u661f\u9ad8\u7167","5":"\u6d74\u706b\u91cd\u751f","4":"\u5144\u5f1f\u540c\u5fc3","3":"\u51b3\u6218\u6c99\u57ce","2":"\u5929\u4eba\u5408\u4e00","1":"\u4f20\u5947\u5f52\u6765"}}';

    trim = function(text) {
        return text == null ? "" : text.replace(/(^\s*)|(\s*$)/g, "");
    };

    parseJSON = function(data) {
        if (!data || typeof data !== "string") {
            return null;
        }
        data = trim(data);
        if(window.JSON && window.JSON.parse) {console.log(1)
            return window.JSON.parse(data);
        }
        console.log(2);
        //return (new Function("return " + data))();// 跟下行一个意思
        return eval("(" + oo + ")")
    };
    console.log(parseJSON(oo));

输出  :  Object {gname"屠龙传说"status"1"serversObject}

posted @ 2013-12-03 16:30  楚玉  阅读(589)  评论(0编辑  收藏  举报