There are many library files or many ways to catch json response data from an URL. But here am using core Class(URL) files to catch json reponse in java.

The URL class present in the java core library.

There is no need of another jar file.


http://ampersandacademy.com/demo/json/jsonreponse.php

The above url will generate json response. Java code to catch json response.


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;

public class Header {

	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			URL url = new URL("http://ampersandacademy.com/demo/json/jsonreponse.php");
			BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
			String str = "";
			while (null != (str = br.readLine())) {
				System.out.println(str);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		   
	}
}

output:

{"name":"raja","age":20}