{"succList":[
{"aaaa0":0,"bbbb0":0,"cccc0":0},
{"aaaa1":1,"bbbb1":1,"cccc1":1},
{"aaaa2":2,"bbbb2":2,"cccc2":2}
] }
10,json的组合,返回的结果的值是一个数组
Json代码
<table cellpadding="1" cellspacing="1"> <tr> <td bgcolor="#FFE7CE"> 代码如下</td> <td bgcolor="#FFE7CE">复制代码</td> </tr> <tr> <td colspan="2" valign="top" bgcolor="#FFFFFF" id=copy1727>// 创建json的基本对象
String date = "{}";
JSONObject jsonobj = JSONObject.fromObject(date);
String[] str={"json","ajax","Jquery","javascript"};//数组
jsonobj.put("arr", str);
ArrayList<JSONObject> list = new ArrayList<JSONObject>();//创建队列
for(int i=0; i<3; i ){ //循环
JSONObject json = JSONObject.fromObject(date); //转化的java
json.put("aaaa" i, i);
json.put("bbbb" i, i);
json.put("cccc" i,str ); //添加一个数组
list.add(json);
}
jsonobj.put("succList", list);
System.out.println(jsonobj.toString()); </td> </tr> </table>
结果:
{"arr":["json","ajax","Jquery","javascript"],
"succList":[{"aaaa0":0,"bbbb0":0,"cccc0":["json","ajax","Jquery","javascript"]},
{"aaaa1":1,"bbbb1":1,"cccc1":["json","ajax","Jquery","javascript"]},
{"aaaa2":2,"bbbb2":2,"cccc2":["json","ajax","Jquery","javascript"]}
]}
11,组合,任意的嵌套;
Json代码
<table cellpadding="1" cellspacing="1"> <tr> <td bgcolor="#FFE7CE"> 代码如下</td> <td bgcolor="#FFE7CE">复制代码</td> </tr> <tr> <td colspan="2" valign="top" bgcolor="#FFFFFF" id=copy7423>// 创建json的基本对象
String date = "{}";
JSONObject jsonobj = JSONObject.fromObject(date);
String[] str={"json","ajax","Jquery","javascript"};//数组
//转化java的json嵌套到json中
JSONObject jsonDemo = JSONObject.fromObject(date);
for(int n=0;n<3;n ){
jsonDemo.put("组合" n, n);
}
ArrayList<JSONObject> list = new ArrayList<JSONObject>();//创建队列
for(int i=0; i<3; i ){ //循环
JSONObject json = JSONObject.fromObject(date); //转化的java
json.put("aaaa" i, jsonDemo); //嵌套的json
json.put("bbbb" i, "java");
json.put("cccc" i,str ); //值为一个数组
list.add(json);
}
jsonobj.put("succList", list);
System.out.println(jsonobj.toString()); </td> </tr> </table>
运行结果:
{"succList":
[{"aaaa0":{"组合0":0,"组合1":1,"组合2":2},
"bbbb0":"java","cccc0":["json","ajax","Jquery","javascript"]},
{"aaaa1":{"组合0":0,"组合1":1,"组合2":2},
"bbbb1":"java","cccc1":["json","ajax","Jquery","javascript"]},
{"aaaa2":{"组合0":0,"组合1":1,"组合2":2},
"bbbb2":"java","cccc2":["json","ajax","Jquery","javascript"]}
]}
您可能感兴趣的文章:
BOM与DOM的区别分析
JQuery将文本转化成JSON对象需要注意的问题
有关php操作json格式数据的实例代码
基于jquery异步传输json数据格式实例代码
php跨域调用json的例子
jQuery中验证表单提交方式及序列化表单内容的实现
jQuery表格插件 ayGrid
浅析ajax请求json数据并用js解析(示例分析)
JSP入门教程(1)-基础知识
用jquery和json从后台获得数据集的代码