Skip to content

Instantly share code, notes, and snippets.

@nickyrabit
Last active April 15, 2019 10:59
Show Gist options
  • Save nickyrabit/56e0b82ddc27d310f49a11172ef7a0b0 to your computer and use it in GitHub Desktop.
Save nickyrabit/56e0b82ddc27d310f49a11172ef7a0b0 to your computer and use it in GitHub Desktop.
How to handle null json key when processing JSON Object in Java and Android
//in my example im creating a json object from json array
JSONObject object = jArr.getJSONObject(i);
//getting an JSONArray from JSONObject
JSONArray roleJSONArray = object.getJSONArray("roles");
//This is where i check the null json object if "location" value comes null
//Step 1: check if its null using isNull
if(object.isNull("location")){
//override the key value from location to another value
object.put("location", "N/A");
}
@nickyrabit
Copy link
Author

nickyrabit commented Apr 15, 2019

lol, the number of times I revise my own gist...hahaha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment