使用alibaba的json工具将String类型转为JSONArray类型
转化流程:先将输入流转为String类型,再使用alibaba的json转换工具,将字符串转化为json数组
SensorDevices sensorDevices = new SensorDevices();
request.setCharacterEncoding("utf-8");
JSONObject json = new JSONObject();
JSONArray list = new JSONArray();
BufferedReader br;
String line = null;
String brStr = null;
String jsonStr = null;
String jsonStr2 = null;
try {
br = new BufferedReader(new InputStreamReader((ServletInputStream) request.getInputStream()));
StringBuilder sb = new StringBuilder();
// line = br.readLine();
while ((line = br.readLine()) != null) {
sb.append(line);
brStr = sb.toString();
}
list = JSONArray.parseArray(brStr);
} catch (IOException e) {
e.printStackTrace();
}
// System.out.println("+++++++++这是brStr:" + brStr);
// System.out.println("+++++++++这是JSON:" + json);
// 遍历json数组
System.out.println("+++++++++这是JSONArray:" + list); 相关推荐
Lzs 2020-10-23
聚合室 2020-11-16
零 2020-09-18
Justhavefun 2020-10-22
ChaITSimpleLove 2020-10-06
周游列国之仕子 2020-09-15
afanti 2020-09-16
88234852 2020-09-15
YClimb 2020-09-15
风雨断肠人 2020-09-04
卖口粥湛蓝的天空 2020-09-15
stulen 2020-09-15
pythonxuexi 2020-09-06
abfdada 2020-08-26
梦的天空 2020-08-25