Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Have you heard of <a href="https://code.google.com/p/google-gson/" rel="nofollow">Gson</a>? It helps you to parse JSON object to Java object. Your JSON data is a bit weird though. Why the responded notifications didn't get to store in an array but in separate JSON objects?</p> <p>What I meant is why not:</p> <pre><code>{ "notification": [ { "id":"17546", "uID":"6698", "text":"Earned 22 points for searching", }, { "id":"17545", "uID":"6698", "text":"Earned 1 point for searching", }, { "id":"17544", "uID":"6698", "text":"Earned 1 point for searching", }, { "id":"17543", "uID":"6698", "text":"Earned 1 point for searching", }, { "id":"17528", "uID":"6698", "text":"Earned 1 point for searching", } ], "notificationCount": 5 } </code></pre> <p>If you can have something like this, GSON is very easy to use. Create these Java Beans:</p> <pre><code>public class JsonObj { private List&lt;Notification&gt; list; private int notificationCount; public JsonObj { } public JsonObj(List&lt;Notification&gt; list, int notificationCount) {...} public List&lt;Notification&gt; getList() {...} .... get/set methods } public class Notification { private Long id; private Long uID; private String text; public Notification { } public Notification(Long id, Long uId, String text) {...} public Long getId() {...} .... get/set methods } </code></pre> <p>Then when you get the Json String, just do:</p> <pre><code>JsonObj obj = new Gson().fromJson(jsonData, JsonObj.class); </code></pre> <p>To get the text:</p> <pre><code>String txt = obj.getList().get(index).getText(); </code></pre> <p>Note: you can also get notificationCount by <code>getList().size();</code></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