I'm now trying to get JSON Object with using HTTP request in Java cord.
I want to know how I can get response or JSON object in the following cord.
Please let me know.
(In this program, I try to get Wikipedia categories of the article "New York". )
String requestURL = "http://en.wikipedia.org/w/api.php?action=query&prop=categories&format=json&clshow=!hidden&cllimit=10&titles=" + words[i];
URL wikiRequest = new URL(requestURL);
URLConnection connection = wikiRequest.openConnection();
connection.setDoOutput(true);
/**** I'd like to get response here. ****/
JSONObject json = Util.parseJson(response);
解决方案
Scanner scanner = new Scanner(wikiRequest.openStream());
String response = scanner.useDelimiter("\\Z").next();
JSONObject json = Util.parseJson(response);
scanner.close();