アリfastJsonのいくつかのJson方式

6623 ワード

public class Main {
    @Test
    public void main() {
   // write your code here
        int sum=0;
        for(int i=0;i<5;i++){
            sum+=i;
        }
        System.out.print(sum);
    }

    public void JSONTest(){
        String str="{\"errCode\":\"0\",\"id\":\"10\"}";
        System.out.print(str);
    }
    @Test
    public void setFastJson(){


        JSONObject root =new JSONObject();//             
        root.put("errCode",1);
        root.put("errMsg","      ");
        JSONArray dateArr = new JSONArray();
        JSONObject rootZhangchao = new JSONObject();
        rootZhangchao.put("userName","  ");
        rootZhangchao.put("position","java  ");
        rootZhangchao.put("webAddress","www.itmayiedu.com");
        dateArr.add(rootZhangchao);
        root.put("date",dateArr);

        System.out.print(root.toJSONString());
    }
    @Test
    public void mapJson(){
        Map root = new HashMap<>();
        root.put("errCode",1);
        root.put("errMsg","      ");
        List> userList = new ArrayList<>();
        Map rootzhangchao = new HashMap<>();
        rootzhangchao.put("id",1);
        rootzhangchao.put("userName","  ");
        rootzhangchao.put("position","java  ");
        rootzhangchao.put("webAdrress","www.itmayiedu.com");

        userList.add(rootzhangchao);
       root.put("date", userList);
        System.out.print(root.toString());

    }
    @Test
    public void entityJson(){
        Entity entity = new Entity();
        entity.setErrCode("0");
        entity.setErrMsg("      ");
        List userList = new ArrayList<>();
        User user = new User();
        user.setId(1);
        user.setUserName("  ");
        user.setPosition("java    ");
        user.setWebAdrress("www.itmayiedu.com");
        userList.add(user);
        entity.setDate(userList);
        System.out.print(entity.toString());
    }
}

 :    ,      :