//例子
json="[{\"signal\":1,\"speed\":2,\"bl\":3,\"blf\":true,\"lpf\":true,\"nmt\":true,\"signs\":1,\"devicesID\":\"123456\",\"visitorsName\":\"李四\",\"sign\":1,\"startTime\":8888888888,\"endTime\":99999999999,\"doc\":[{\"x\":10},{\"x\":20}]}]";
/*
* 将json数据变成数组,然后循环获取
*/
JSONArray jsonArray = JSONArray.fromObject(json);
Object[] os = jsonArray .toArray();
for (int i = 0; i < os.length; i++) {
String testTime=null;
JSONObject jsonObj = JSONObject.fromObject(os[i]);
Integer signal = (Integer)jsonObj.get("signal");
Integer speed = (Integer)jsonObj.get("speed");
Integer bl = (Integer)jsonObj.get("bl");
Boolean blf = (Boolean)jsonObj.get("blf");
Boolean lpf = (Boolean)jsonObj.get("lpf");
Boolean nmt = (Boolean)jsonObj.get("nmt");
String devicesID = (String)jsonObj.get("devicesID");
sign = (Integer)jsonObj.get("signs");
Long time = (Long)jsonObj.get("startTime");
String startTime = Dateutil.getDatess(time);
time = (Long)jsonObj.get("endTime");
Object object10 = jsonObj.get("doc");
Object[] o = doc .toArray();
for (int j = 0; j < o.length; j++) {
JSONObject jsonObj1 = JSONObject.fromObject(o[j]);
Integer x= (Integer)jsonObj1.get("x");
}
}
<!-- json依赖 -->
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>