You can use one of the many available Json Parser for the purpose. I have personally used following in simple applications. You can refer this tutorial:
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
You might need to install dependencies first:
In case you are on maven, use following
to set a proper environment for the compiler, in order to recognize the JSON's classes. If you want to built your project via Maven, you should add the following dependency to your pom.xml:
1
2
3
4
5
|
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1</version>
</dependency>
|
Otherwise, you have to add the newest version of json-simple-1.1.1.jar in your CLASSPATH.
First you need to Declare an instance of the JSONParser:
JSONParser parse = new JSONParser();
Then, Convert the string objects into JSON objects:
JSONObject jobject = (JSONObject)parse.parse(inline);
If you view the JSON structure, it will be something like this:
Then you can convert the JSON object into JSONArray
JSONArray jsonarray = (JSONArray) jobj.get(“results”);
Now you can use as per your need, for eg.
get the elements within the results array. Here is how you do it: