转化流程:先将输入流转为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);

 

相关文章:

  • 2021-11-17
  • 2021-06-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-25
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-13
  • 2021-10-20
  • 2021-07-21
相关资源
相似解决方案