While great, Jsoup is a HTML parser, not a JSON parser, so it is useless in this context. If you ever attempt it, Jsoup will put the returned JSON implicitly in a <html><head>
and so on. You don't want to have that. Gson is a JSON parser, so you definitely need it.
Your concrete problem is likely that you don't know how to feed an URL returning a JSON to Gson. In that case, you need to use URL#openStream()
to get an InputStream
of it and use InputStreamReader
to decorate it into a Reader
which finally can be fed to Gson#fromJson()
which accepts a Reader
.
InputStream input = new URL("http://example.com/foo.json").openStream();
Reader reader = new InputStreamReader(input, "UTF-8");
Data data = new Gson().fromJson(reader, Data.class);
// ...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…