soapergem
0
Q:

python json check if key exists

import json
  if 'id' not in dest:
      dest['id'] = -1
    targetId = dest['id']
1
json_string = """{"a": 1, "b": 2, "c": 3}"""
a_dictionary = json.loads(json_string)

b_in_dict =  "b" in a_dictionary
0
// JSONObject class has a method named "has":
// http://developer.android.com/reference/org/json/JSONObject.html#has(java.lang.String)
// Returns true if this object has a mapping for name. The mapping may be NULL.
if (json.has("status")) {
   String status = json.getString("status"));
}

if (json.has("club")) {
   String club = json.getString("club"));
}
0
b_in_dict =  "b" in a_dictionary
0

New to Communities?

Join the community