How to check if a JSON key exists?

So, I get some JSON values from the server but I don’t know if there will be a particular field or not.

So like:

{ "regatta_name":"ProbaRegatta",

And sometimes, there will be an extra field like:

{ "regatta_name":"ProbaRegatta",

I would like to check if the field named “club” exists so that at parsing I won’t get

org.json.JSONException: No value for club


JSONObject class has a method named “has”:

Returns true if this object has a mapping for name. The mapping may be NULL.

Leave a Reply

Your email address will not be published. Required fields are marked *