We are about to switch to a new forum software. Until then we have removed the registration on this forum.
This is an excerpt of a JSON file I'm working on with Processing
"headlineReview":{
"text":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus gravida dignissim neque, eu scelerisque lacus.",
"author":"Lorem ipsum"
},
"classicalReview":null,
"classicalReviewUri":null,
Sometimes the "headlineReview" is null (like "classicalReview") and some other times it contains a String (as shown above). How do I check if that particular field is null? I already tried with .getString(), .getBoolean() etc... but I always get an error so I cannot run an if statement.
Answers
pseudo code:
String test=null;
test=cccc.getString();
if(test!=null){
....
?
Also:
Maybe look at try catch.....
As I said, the problem is that if I use .getString() I got the error "JSONObject["classicalReview"] is not a String"
According to JSONObject's getString() reference here:
https://processing.org/reference/JSONObject_getString_.html
It got an override version w/ 2 arguments. In which we can set up an optional return value for when the "key" doesn't exist. :-B
Thanks @GoToLoop, didn't see that!