json To STR
<script type="text/javascript">
function JsonToStr(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] = JsonToStr(o[i]);
r[r.length] = ",";
}
r[r.length - 1] = "}"
} else {
r[0] = "["
for (var i = 0; i < o.length; i++) {
r[r.length] = JsonToStr(o[i]);
r[r.length] = ",";
}
r[r.length - 1] = "]"
}
return r.join("");
}
return o.toString();
}
window.onload = function () {
var str = '{ "people": [{ "firstName": "Brett", "lastName":"McLaughlin", "email": "aaaa" },{ "firstName": "Jason", "lastName":"Hunter", "email": "bbbb"},{ "firstName": "Elliotte", "lastName":"Harold", "email": "cccc" }]} ';
alert(JsonToStr( eval('('+str+')')));
// alert(eval(str));
//alert(JsonToStr(str));
}
</script>
一只站在树上的鸟儿,从来不会害怕树枝会断裂,因为它相信的不是树枝,而是它自己的翅膀。与其每天担心未来,不如努力做好现在。