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",
  "country":"Congo",
  "status":"invited"
}

And sometimes, there will be an extra field like:

{ "regatta_name":"ProbaRegatta",
  "country":"Congo",
  "status":"invited",
  "club":"somevalue"
}

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

13 Answers
13

Leave a Comment