import java.net.HttpURLConnection; import java.net.URL; import java.util.Iterator; import java.util.Scanner; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; public class App { public static void main(String[] args) throws Exception { System.out.println("JSON olvasás"); URL url = new URL("http://localhost:8000/api/employees"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.connect(); int responsecode = conn.getResponseCode(); if(responsecode != 200) { throw new RuntimeException("HttpResponseCode: " + responsecode); }else { Scanner sc = new Scanner(url.openStream(), "UTF-8"); String inline = ""; while(sc.hasNext()) { inline += sc.nextLine(); } JSONParser parse = new JSONParser(); Object obj = parse.parse(inline); JSONArray ja = (JSONArray) obj; Iterator itr = ja.iterator(); while(itr.hasNext()) { JSONObject obj2 = (JSONObject) itr.next(); System.out.println( obj2.get("name") ); } } } }