I have a JSONArray emitted by a servlet, like a REST API. I have followed a few links and tried to parse this URL. I am able to receive the URL and print it out from my client servlet, but how do I parse it? So far this is what I have
PrintWriter out = response.getWriter();
response.setContentType("application/json");
response.setHeader("Cache-Control", "nocache");
response.setCharacterEncoding("utf-8");
String out1 = new Scanner(new URL("http://localhost:8080/myproject/servletone").openStream(), "UTF-8").useDelimiter("\\A").next();
out.print(out1);
The output is a json array as follows,
[{"name":"abc","age":"80","gender":"male"},{"name":"hello","age":"45","gender":"female"}]
I need to be able to access each of the individual elements name, age, gender in each of the arrays.