java 字符串的json格式数据转换成Map集合

1.如何是maven项目的在pom.xml加入

dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
</dependency>

依赖.如不是自行下载jar包

2.示例如下

 1 public static void main(String[] args) {
 2         
 3         String detail="{"result":0,"msg":"成功","info":{"saleUnit":"","weight":"0.04"}}";
 4         
 5      6         
 7         JSONObject json=new JSONObject(detail);
 8         Map<String,Object> map=new HashMap<String, Object>();
 9         Iterator it = json.keys();
10         while (it.hasNext()) {  
11            String key = (String) it.next();  
12            Object value = json.get(key);  
13            map.put(key, value);
14         }
15         System.out.println(map.get("info"));
16     }
原文地址:https://www.cnblogs.com/taobd/p/7132184.html