This might be a dumb question but what is the simplest way to read and parse JSON from URL in Java?
In Groovy, it's a matter of few lines of code. Java examples that I find are ridiculously long (and have huge exception handling block).
All I want to do is to read the content of this link.
I have done the json parser in simplest way, here it is
this class returns the json object from the url
and when you want the json object you just call this class and the method in your Activity class
my code is here
here the "json key" is denoted that the key in your json file
this is a simple json file example
Here "json" is key and "hi" is value
This will get your json value to string content.
Here are couple of alternatives versions with Jackson (since there are more than one ways you might want data as):
And specifically the usual (IMO) case where you want to deal with Java objects, can be made one liner:
Other libs like Gson also support one-line methods; why many examples show much longer sections is odd. And even worse is that many examples use obsolete org.json library; it may have been the first thing around, but there are half a dozen better alternatives so there is very little reason to use it.