标签:size style 一个 ace artifact new result 数据 class
String p1 = "{\"name\": \"lisi\", \"age\": 18}"; /*Person p = new Person(); String pno = p1.substring(1, p1.length() - 1); System.out.println(pno); String[] split = pno.split(","); String[] name = split[0].split(":"); p.setName(name[1].trim()); String[] age = split[1].split(":"); p.setAge(Integer.parseInt(age[1].trim())); System.out.println(p);*/ Person p = JSON.parseObject(p1,Person.class); System.out.println(p); Person p2 = new Person("laowang", 30); String result = JSON.toJSONString(p2); System.out.println(result); //接受来自js的数据 //给js发送数据 //将js中的数组字符串,转化为java中的List String l1 = "[{\"name\":\"laowang\",\"age\":18},{\"name\":\"laoma\",\"age\":30}]"; List<Person> list = JSON.parseArray(l1, Person.class); System.out.println(list.get(0)); System.out.println(list.get(1)); //将java的list转化为json格式的数组字符串 List l2 = new ArrayList<>(); l2.add(new Person("zhangsan", 5)); l2.add(new Person("lisi", 6)); String result2 = JSON.toJSONString(l2); System.out.println(result2);
标签:size style 一个 ace artifact new result 数据 class
原文地址:https://www.cnblogs.com/aknife/p/10816832.html