Last active
April 15, 2019 10:59
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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"); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
lol, the number of times I revise my own gist...hahaha