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();
}
}
}