组装json
package com.learn.json;import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;/*** * @classDesc: 功能描述:(組裝json)* */
public class JSONTest2 {public static void main(String[] args) {JSONObject jsonObject = new JSONObject();JSONArray sitesArray = new JSONArray();JSONObject bean1 = new JSONObject();bean1.put("name", "百度");bean1.put("url", "http://www.baidu.com");sitesArray.add(bean1);JSONObject bean2 = new JSONObject();bean2.put("name", "阿里巴巴1");bean2.put("url", "http://www.alibaba.com");sitesArray.add(bean2);jsonObject.put("sites", sitesArray);System.out.println(jsonObject.toJSONString());}}
?
總結
- 上一篇: 解析json
- 下一篇: 数组的定义格式一_动态初始化