这里我使用到的jar是
<!-- https://mvnrepository.com/artifact/net.sf.json-lib/json-lib -->
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<! --
如果报出 Missing artifact net.sf.json-lib:json-lib:jar:2.4
<classifier>jdk15</classifier><!--指定jdk版本-->
-->
</dependency>
// 批量数据操作取值和传值的时候可以使用到
public static void main(String[] args) {
String jsonStr = "{'head':{'version':'1'},'dataList':{'resCode':'ss','list':[{'name':'file1','type':'0'},{'name':'file2','type':'1'}]}}";
JSONObject dataJson= JSONObject.fromObject(jsonStr);
JSONObject dataList=dataJson.getJSONObject("dataList");
JSONArray list=dataList.getJSONArray("list");
JSONObject info=list.getJSONObject(1);
String name=info.getString("name");
String type=info.getString("type");
System.out.println(name+"\n"+type);
//String name = jsonObject.getString("name");
//System.out.println(name);
}