java - how to avoid a Json array when i'm fetching data -


I'm bringing Jason data to Java, and my Jason has a different structure and it's not always the case. Example:

  {"0": {"id" = "255", name = "example"}, "1": {"news_id": "47221", "news_infos": {"Title": "test", "date": "2014-05-14 17:44:02", "shared": "47"}, "website": "test.it"}, "3 ": {" Id "=" 55885 ", name =" afu "}}   

This is just an example. What I need to know is how can I leave another, we believe that the second one is Jason Array. This is an example of what I am doing in Java;

 for  (int i = 0; i & lt; jObj.length (); i ++) {try {JSONObject obj = jObj.getJSONObject (i); // suppose that every entry in JSN is an object and does not have a Jason Array (! Obj.isNull ("titrenews")) {home at home = new home (); Log.i ("Infos", "Yes"); Home.setNomC (obj.getString ("titrenews")); home.setPhotoAr (photoNews); Home.setText (obj.getString ("textnews")); Home.setNbrSick (obj.getString ("sicks")); HomeList.add (home); }} Hold (JSOXECTION E) {E.PintstacksTrace (); } Hold (unsupported encoding exception e) {e.printStackTrace (); }}   

To solve this problem, I have a Jason data made from JsonObject and JsonArray, and what I want is to leave the jsonArray entry and avoid it

So any solution please!

Try this approach: {if (Obj instanceof JSONObject) {// do something else else} if (obj instanceof JSONArray) {continue; // skip}}

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -