通过数组实现
最后调用JSON.stringify(data)方法
- <div id="json" style="width:100%;height:50px;background-color:yellow">
-
- </div>
-
- <script>
-
- var params = [];
- for(var i = 0; i < 3; i++){
- var param = [];
- param.push("one");
- param.push("two");
- param.push("three");
- params.push({"group":i,"param":param});
- }
-
- var json = JSON.stringify(params);
- alert(json);
-
- var jsonElem = document.getElementById("json");
- jsonElem.innerHTML = json;
-
- </script>
-
- <!--
- 组成的json串:
- [{"group":0,"param":["one","two","three"]},{"group":1,"param":["one","two","three"]},{"group":2,"param":["one","two","three"]}]
- -->