java创建json对象数组_java 创建json对象

// 声明两个json数组

JSONArray gResTable = new JSONArray();

JSONArray gCmtTable = new JSONArray();

// 声明json对象

JSONObject outData = new JSONObject();

//把json数组加到json对象中

outData.put("ResTable", gResTable);

outData.put("CmtTable", gCmtTable);

//此时创建出来的如下:jsonData={"ResTable":[],"CmtTable":[]};

把json数据加到json数组中

for (int i = 0; i < 2; i ++)

{

JSONObject node = new JSONObject();

node.put("thumb_path", "./Image/" + i +".gif");

node.put("flash_path", "./Image/" + i +".gif");

node.put("desc1", "可疑车辆" + i);

node.put("desc2", "");

node.put("desc3", "");

node.put("desc4", "");

node.put("title", "hello");

node.put("upload_time", (new java.util.Date()).toString());

node.put("uploader", "王二");

gResTable.put(node);

}

for (int i = 0; i < 2; i ++)

{

JSONObject node = new JSONObject();

node.put("logo_path", "./Image/" + i +".gif");

node.put("comment", "hello");

node.put("comment_time", (new java.util.Date()).toString());

node.put("author", "王二");

gCmtTable.put(node);

}

创建出来的json格式如下:

/*

jsonData={"ResTable":[

{"upload_time":"Sat May 26 20:16:37 CST 2012","title":"hello","flash_path":"./Image/0.gif","uploader":"王二","thumb_path":"./Image/0.gif","desc3":"","desc4":"","desc1":"可疑车辆0","desc2":""},

{"upload_time":"Sat May 26 20:16:37 CST 2012","title":"hello","flash_path":"./Image/1.gif","uploader":"王二","thumb_path":"./Image/1.gif","desc3":"","desc4":"","desc1":"可疑车辆1","desc2":""}],

"CmtTable":

[{"author":"王二","logo_path":"./Image/0.gif","comment":"hello","comment_time":"Sat May 26 20:16:37 CST 2012"},

{"author":"王二","logo_path":"./Image/1.gif","comment":"hello","comment_time":"Sat May 26 20:16:37 CST 2012"}

]};

*/

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值