Java, Parse JSON Objects that I know are null Java, Parse JSON Objects that I know are null json json

Java, Parse JSON Objects that I know are null


Use JSONObject.optString(String key) or optString(String key, String default).

Edit: ... or isNull(String key), of course :)


I think you'll need to format the JSON differently;

for an array of promotions

{promotions:[{promotion:null}, {promotion:5000}]}

for a single promotion

{promotion:null}

edit: depending on which json api you're using, there might be a null check. Google's gson library has an .isJsonNull() method


Uh...I don't think that is a properly formatted JSON string. [] indicates an array, which doesn't have any kind of key=>value pairing like an object does. What I think you want would be {"promotion":null}, which then your code snippet likely would work.