import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.util.Iterator; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; public class App { public static void main(String[] args) throws Exception { System.out.println("REST API olvasás"); URL url = new URL("https://jsonplaceholder.typicode.com/users/"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.connect(); int responseCode = conn.getResponseCode(); if (responseCode != 200) { throw new RuntimeException("Http válasz: " + responseCode); }else { Object obj; JSONArray ja; try { JSONParser parser=new JSONParser(); obj = parser.parse(new InputStreamReader(conn.getInputStream())); ja = (JSONArray) obj; } catch ( ParseException ex) { throw new IOException("JSON parser error, " + ex.getMessage(),ex); } Iterator itr = ja.iterator(); while(itr.hasNext()) { JSONObject obj2 = (JSONObject) itr.next(); System.out.println( obj2.get("name") ); System.out.println( ((JSONObject) obj2.get("address")).get("city") ); } } } }