标签:code fast 转换 类型 class maps system parse tst
Person p = new Person("费哥", 26);
String jsonString = JSON.toJSONString(p);
System.out.println(jsonString);
Person p = new Person("费哥", 26);
String jsonString = JSON.toJSONString(p);
JSONObject jsonObject = JSON.parseObject(jsonString);
System.out.println(jsonObject.getString("name"));
Person p = new Person("费哥", 26);
String jsonString = JSON.toJSONString(p);
Person person = JSON.parseObject(jsonString, Person.class);
Person p1 = new Person("费哥", 26);
Person p2 = new Person("费哥2", 26);
List<Person> list = new ArrayList<Person>();
list.add(p1);
list.add(p2);
String jsonString = JSON.toJSONString(list);
Person p1 = new Person("费哥", 26);
Person p2 = new Person("费哥2", 26);
List<Person> list = new ArrayList<Person>();
list.add(p1);
list.add(p2);
String jsonString = JSON.toJSONString(list);
List<Person> list2 = JSON.parseArray(jsonString, Person.class);
Person p1 = new Person("费哥", 26);
Person p2 = new Person("费哥2", 26);
List<Person> list = new ArrayList<Person>();
list.add(p1);
list.add(p2);
String jsonString = JSON.toJSONString(list);
JSONArray jsonArray = JSON.parseArray(jsonString);
String objString = "[{‘zhangsan‘:{‘name‘:‘zhangsan‘,‘age‘:12},‘lishi‘:{‘name‘:‘lishi‘,‘age‘:12}}]";
List<Map<String, Person>> list2 = JSON.parseObject(objString, new TypeReference<List<Map<String,Person>>>(){});
System.out.println(list2.toString());
说明:TypeReference用于复杂类型的转换。
标签:code fast 转换 类型 class maps system parse tst
原文地址:https://www.cnblogs.com/feiqiangsheng/p/13303063.html