Here you can find the source of readJsonFromUrl(String urlString)
Parameter | Description |
---|---|
urlString | a parameter |
Parameter | Description |
---|---|
Exception | an exception |
public static JsonObject readJsonFromUrl(String urlString) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import com.google.gson.Gson; import com.google.gson.JsonObject; public class Main { public static Gson gson = new Gson(); /**// www .j a va2 s . c o m * Opens a buffered reader, reads the URL and closes the buffered reader. * @param urlString * @return * @throws Exception */ public static JsonObject readJsonFromUrl(String urlString) throws IOException { InputStreamReader inStream = null; try { URL url = new URL(urlString); inStream = new InputStreamReader(url.openStream()); return gson.fromJson(inStream, JsonObject.class); } finally { if (inStream != null) inStream.close(); } } }