JSoup: Requesting JSON response
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 ?
You can fetch JSON or other data format using this:
// JSON example
String json = Jsoup.connect(url).ignoreContentType(true).execute().body();
Try Like This
Use Header "Accept:text/javascript"
String InboxJson=Jsoup.connect("https://www.fiverr.com/conversations/Json")
.timeout(1000000)
.header("Accept", "text/javascript")
.userAgent("Mozilla/5.0 (Windows NT 6.1; rv:40.0) Gecko/20100101 Firefox/40.0")
.get()
.body()
.text();
I don't think Jsoup will execute Javascript. If the provided URL returns any non-html text, I believe Jsoup will just wrap it in a body tag or something similiar.
See this post for a suggestion
You should use a JSON library to process JSON Data.
Here are some: Click
精彩评论