0

I got a json response as

 {
    "tasks": null,
    "projects": null

  } 

how to check if the array has null values and handle the case??

Thanks:)

7
  • array means? you mean response null or particular field null? Commented Nov 28, 2013 at 6:20
  • @SathishKumar: Assume that "tasks" and "projects" are normally arrays, but in this example they are both set to null. Commented Nov 28, 2013 at 6:21
  • particular field.here tasks is json array.It returns the value null when there is no data. Commented Nov 28, 2013 at 6:21
  • 1
    stackoverflow.com/questions/10588763/… check this, Commented Nov 28, 2013 at 6:23
  • Hi Can you Update The full String With Root This data coming from the Array Or Jsonobject Commented Nov 28, 2013 at 6:27

4 Answers 4

2

Try this,

jsonObject.isNull("field-name")

Reference: JSON null handling and this.

Sign up to request clarification or add additional context in comments.

Comments

0
Try This
=============
try {
        String url;
    JSONObject JsonData = new JSONObject("YOUR FULL JSONSTRING");
    JSONArray webData = JsonData.getJSONArray("YOUR ROOT NAME OF YOUR JSON RESPONSE");

    for(int i=0;i<webData.length();i++)
    {
        JSONObject TeampObj = webData.getJSONObject(i);
        if(TeampObj.getString("tasks").trim().length()>0)
        {
            //store data in arrylist or string array

        }
        if(TeampObj.getString("projects").trim().length()>0)
        {
            //store data in arrylist or string array
        }
    }
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

1 Comment

Give me your Fuul String i send you Full Parsing
0

Try..

 public boolean isNull (String name)

Added in API level 1 Returns true if this object has no mapping for name or if it has a mapping whose value is NULL.

Comments

0

use try ... catch to handle the exception:

Try{

   // parsing data

}catch (NullPointerException e) {
    e.printStackTrace();
} catch (Exception e) {
    e.printStackTrace();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.