1

My request body contains JSON. i have to read that JSON save it as JSON object. And i don't have any pojo class representing the data in json. i tried this , and this and i am using com.ibm.json.java.JSONObject.i have tried this ,

BufferedReader ne = req.getReader();

    StringBuffer jb = new StringBuffer();
    try {
      BufferedReader reader = req.getReader();
      while ((line = reader.readLine()) != null)
        jb.append(line);
    } catch (Exception e) { /*report an error*/ }

      JSONObject jsonObject = new JSONObject();
      jsonObject.put("data", jb.toString());

above implementation is dumb because i am converting request header to string and adding it to jsonobject.

Community
  • 1
  • 1

1 Answers1

0

I think you should use public static JSONObject parse( java.lang.String str) in class JSONObject .Also there is no need to convert Reader to String as there are overloaded methods in JSONObject which take Inputstream and Reader eg public static JSONObject parse( java.io.Reader reader)