jquery打印某个json对象的方法:
<script>
var jsonToString=typeof JSON !="undefined"? JSON.stringify :function(obj){
var arr =[];
$.each(obj,function(key, val){
var next = key +": ";
next += $.isPlainObject(val)? jsonToString(val): val;
arr.push( next );
});
return"{ "+ arr.join(", ")+" }";
};
var jsonstring = {
"modeldata" : [ {
"chart.data" : 12,
"chart.colors" : "red",
"chart.labels" : "John(12%)",
"chart.exploded" : 10
}, {
"chart.data" : 18,
"chart.colors" : "blue",
"chart.labels" : "Richard(18%)",
"chart.exploded" : 20
}, {
"chart.data" : 25,
"chart.colors" : "green",
"chart.labels" : "James(25%)",
"chart.exploded" : 20
}, {
"chart.data" : 45,
"chart.colors" : "pink",
"chart.labels" : "Green(45%)",
"chart.exploded" : 20
} ],
"operate" : [ "hello" ]
};
alert(JSON.jsonToString(jsonstring));
</script>