a json file is located online, and i want to read the data from that json file using java.
example json file which is available online :jscon file link
thank you
a json file is located online, and i want to read the data from that json file using java.
example json file which is available online :jscon file link
thank you
URL url = new URL("http://rate-exchange.appspot.com/currency?from=USD&to=EUR&q=3");
URLConnection yc = url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null){
System.out.println(inputLine);
}
in.close();
Gson gson = new Gson();
Rate r = gson.fromJson(inputLine,Rate.class);
First obtain the string directly from the URL. I believe you could use this:
Then from the string use the json library to build the json object. You might look into gson for more complex serialization.