JSoup: Requesting JSON response

Jean-Philippe Encausse picture Jean-Philippe Encausse · Aug 20, 2011 · Viewed 30.6k times · Source

I'm using JSoup to authenticate then connect to a website. Some URL have a JSON response (because part of the site is in AJAX). Can JSoup handle JSON response ?

Connection.Response doc = Jsoup.connect("...")
                               .data(...)
                               .cookie(...)
                               .header(...)
                               .method(Method.POST)
                               .execute();
String result = doc.body()

In my case body is "".

  • Is it because JSoup don't know how to handle JSON ? (offcourse there is no )
  • Or because there is an error in my request ?

Is there JSoup like libraries for JSON ?

Answer

Anchor picture Anchor · Jan 16, 2014

You can fetch JSON or other data format using this:

// JSON example
String json = Jsoup.connect(url).ignoreContentType(true).execute().body();