0

I am trying to parse the JSON data using java servlet to have the data display in a table. I want my column to have for columns: Firstname, Lastname, phone, country

I far manage to connect and able to access the JSON data but I am not sure how to parse the data to a table.

the JSON data look something like this:

{

    "result" : [ {
      "Firstname" : "test",
      "Lastname" : "test",
      "Phone" : "test",
      "Country" : "test",

    }, {
     "Firstname" : "test",
      "Lastname" : "test",
      "Phone" : "test",
      "Country" : "test",
    },

    } ]

}
public class Webapp extends HttpServlet {
    public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException

try{

            String url = "http:test.com";
            URL server = new URL(url);
            HttpURLConnection connection = (HttpURLConnection)server.openConnection();
            connection.connect();
            InputStream file_in = connection.getInputStream();
            BufferedReader in = new BufferedReader(new InputStreamReader(file_in));
            StringBuilder sb = new StringBuilder();
            String line ="";

            while((line = in.readLine())!= null){
                sb.append(line+"\n");

            }
            in.close();
            PrintWriter out = res.getWriter();
            out.println(sb.toString());


        }catch(Exception e){
            e.printStackTrace();
        }
}
}
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
user11766958
  • 409
  • 3
  • 12
  • Did you search "How to parse JSON in Java" ? – AxelH Aug 13 '19 at 06:38
  • Then, you mention a table, you mean in a database ? Then you should check JDBC – AxelH Aug 13 '19 at 06:38
  • Another possible duplicate: [Parsing JSON data in Java](https://stackoverflow.com/q/20181844/3345375) with [this answer](https://stackoverflow.com/a/20181943/5874233) (thanks to [Jaypal Sodha](https://stackoverflow.com/users/5874233/jaypal-sodha) for mentioning it) – jkdev Aug 13 '19 at 07:02

0 Answers0