Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to detect a missing key/value #13

Open
wvdvegt opened this issue Apr 9, 2018 · 2 comments
Open

How to detect a missing key/value #13

wvdvegt opened this issue Apr 9, 2018 · 2 comments

Comments

@wvdvegt
Copy link

wvdvegt commented Apr 9, 2018

Hi

For a swagger related project I need to detect the absence of some keys (like 'error').
What is the correct way to check the absence of keys?

@Bunny83
Copy link
Owner

Bunny83 commented Apr 10, 2018

Sure, whenever you access a key that doesn't exist the JSONObject will return a JSONLazyCreator. JSONNode has a custom == operator that will return true when you compare a lazy creator instance against null. So just do

If (N["error"] == null)

@devingDev
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants