Bunny83 / SimpleJSON

A simple JSON parser in C#
MIT License
735 stars 294 forks source link

How to detect a missing key/value #13

Open wvdvegt opened 6 years ago

wvdvegt commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

http://wiki.unity3d.com/index.php/SimpleJSON