Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><em>Just a starting note: the JSON you put in request is not a valid JSON, but can be easily fixed adding a brace (I used fixed JSON in my answer).</em></p> <p>I suggest you to parse your JSON this way. Declare the following classes.</p> <hr> <pre><code>public class Container { public int status; public Results results; @Override public String toString() { return "Container [status=" + status + ", results=" + results + "]"; } } </code></pre> <hr> <pre><code>public class Results { public List&lt;ResultItem&gt; resultitems; @Override public String toString() { return "Results [resultitems=" + resultitems + "]"; } } </code></pre> <hr> <pre><code>public class ResultItem { String uri; String path; HashMap metadata; @Override public String toString() { return "ResultItem [uri=" + uri + ", path=" + path + ", metadata=" + metadata + "]"; } } </code></pre> <p>and then call this code:</p> <pre><code>public class Q19684865 { public static void main(String[] args) { String json = " { " + " \"status\":\"200\", " + " \"results\":{ " + " \"resultitems\":[ " + " { " + " \"uri\":\"/document/id/e20a8dad50d91a839c50ab5f323f3df3\", " + " \"path\":\"Data/xyz/abcdata\", " + " \"metadata\":{ " + " \"data/category/item\":\"yahoo/post\", " + " \"ast_id\":\"67677\" " + " } " + " } " + " ] " + " } " + " } "; Container c = new Gson().fromJson(json, Container.class); System.out.println("this is the parsed json: " +c); System.out.println("this is the property 'data/category/item': "+c.results.resultitems.get(0).metadata.get("data/category/item")); } </code></pre> <p>and this is the result:</p> <pre><code>this is the parsed json: Container [status=200, results=Results [resultitems=[ResultItem [uri=/document/id/e20a8dad50d91a839c50ab5f323f3df3, path=Data/xyz/abcdata, metadata={data/category/item=yahoo/post, ast_id=67677}]]]] this is the property 'data/category/item': yahoo/post </code></pre> <p>Explanation: normally you need just POJOs if you do not have particular needs, where POJO field name corresponds to the label of the JSON value. But 'data/category/item' cannot be a valid Java identifier. So I chose to parse to a Map. </p> <p>A second way could be to replace in JSON string your "data/category/item" with a valid Java identifier, "data_category_item" for example or, if you can change JSON origin, do the same at the source. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload