I am working on parsing a JSON in JAVA which has a structure like this,
{
"id": "P410R",
"create_time": "2014-05-29T19:21:34Z",
"update_time": "2014-05-29T19:21:34Z",
"state": "created",
"links": [
{
"href": "url1",
"rel": "self",
"method": "GET"
},
{
"href": "url2",
"rel": "approval_url",
"method": "REDIRECT"
},
{
"href": "url3",
"rel": "execute",
"method": "POST"
}
]
}
I need to obtain links.href where rel = "approval_url"
So far i have been into nested data structure declarations and can not reach to links.href. I am using GSON library and here is what my code looks like:
Gson gson = new Gson();
JsonElement element = gson.fromJson (jsonResult, JsonElement.class); //jsonResult is class object
JsonObject jsonObj = element.getAsJsonObject();
Map jsonJavaRootObject = new Gson().fromJson(jsonObj, Map.class);
ArrayList refUrls = (ArrayList) jsonJavaRootObject.get("links");
// Map gsonStrMap = new Gson().from .fromJson(refUrls.get(1), Map.class);
String result = jsonJavaRootObject.get("links").toString();
//JsonObject jsonObjRefUrl = (JsonObject) refUrls.get(1);