I’m using jsoup to scrape some HTML data and it’s working out great. Now I need to pull some JSON content (only JSON, not HTML). Can I do this easily with jsoup or do I have to do it using another method? The parsing that jsoup performs is encoding the JSON data so it’s not parsing properly with Gson.
Share
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 anInputStreamof it and useInputStreamReaderto decorate it into aReaderwhich finally can be fed toGson#fromJson()which accepts aReader.