使⽤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;
python json字符串转数组String brStr = null;
String jsonStr = null;
String jsonStr2 = null;
try {
br = new BufferedReader(new InputStreamReader((ServletInputStream) InputStream())); 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);
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论