常见的转换工具有:
Jackson:SpringMVC内置的转换工具
jsonlib:Java提供的转换工具(一般不用)
gson:google提供的转换工具(轻量级的框架)
fastjson:Alibaba提供的转换工具(效率高速度快)
1 2 3 4 5 6 |
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.75</version> </dependency> |
1 |
import com.alibaba.fastjson.JSON; |
1 2 3 4 5 6 7 |
String bodyStr = "[{\"DRUG_CODE\":\"5013034DP0\",\"PACKAGE_UNITS\":\"包\",\"number_per_package\":\"1\",\"DRUG_SPEC\":\"15g沪蔡同德\",\"QUANTITY\":\"601\",\"drug_units\":\"包\",\"PACKAGE_SPEC\":\"15g\",\"dispensary\":\"36000201\",\"extend_params\":\"\\\"\\\"\",\"DEPT_NAME\":\"药材科门诊草药房\",\"DEPT_CODE\":\"36000201\"}]"; JSONArray array = JSON.parseArray(bodyStr); Map<String, Object> bodMap = JSON.parseObject(array.getString(0)).getInnerMap(); System.out.println("drug_units:" + bodMap.get("drug_units")); System.err.println(bodMap); |
View Details