2

I have an object which needs 4 parameters to set the values from a JSONObject. But, when I call get(String name) from JSONObject it has 3 values, so that throws a JSONException. Here is an example:

"JSON":{
    "aaa":"111",
    "bbb":"111",
    "ddd":"111"
}

How can set null for a value if the JSON key is non-existant.. not using GSON

2
  • Just set the key of that object to an empty string perhaps? Commented Oct 31, 2016 at 17:02
  • i can't set it. i'm just a receiver for create object for value of JSON and send it. Commented Oct 31, 2016 at 18:59

1 Answer 1

1

like this:

if (jsonObject.has("aaa") {
    this.aaa = jsonObject.getString("aaa");
}
Sign up to request clarification or add additional context in comments.

1 Comment

String test; if (jsonObject.has("test") { this.test= jsonObject.getString("test"); } else { test = ""; } that ok ? @Christian

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.