赞
踩
1.引入pom包
- <!-- 阿里JSON解析器 -->
- <dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>fastjson</artifactId>
- <version>1.2.31</version>
- </dependency>
2.对象之间转化
//Java转成JSON对象
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(dept);
//JSON字符串转换成Java对象
Student student1 = JSONObject.parseObject(jsonStr, Dept.class);
3.demo例子
- public class Demo {
-
- public static void main(String[] args) {
- // Dept dept1 = new Dept("1340327733561737701","1340327733561737701","单位名称1","1","1","单位1");
- // Dept dept2 = new Dept("1340327733561737702","1340327733561737702","单位名称2","2","2","单位2");
- Map<String,Object> map1 = new HashMap<String,Object>(){<
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。