1. 程式人生 > >JSON.stringify,定義陣列前需 data=[]

JSON.stringify,定義陣列前需 data=[]

<script>


alert("test");
var test={};
test.count=3;
alert(test.count);
test.data=[];
test.data[0]=1;
test.data[1]=2;
alert(test.data[0]+","+test.data[1]);
var toStr = JSON.stringify(test);
alert(toStr);
document.write(toStr);
 
</script>

{"count":3,"data":[1,2]}