We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey guys,
I'm trying to figure out how to know if a JSONObject contains a key. I tried the method myJSON.containsKey("theKey")
, but Processing gives me the error "The function containsKey(String) does not exist".
I've also tried "myJSON.has ("theKey")
" and it does not work either.
It's getting me crazy!!
Thanks for any help!
Answers
What type is myJSON?
Maybe you need to use parseJSONObject first?
well, each json interface is different (depending if its about weather, movies or animals... e.g.)
each json interface holds different keys
so either
you have the documentation of the specification of that json interface
or you use println to just print out the whole json string. Then you can look up the keys you need. And the structure, often there are json-arrays or other json-objects embedded
when you ask for a key that doesn't exist the var should be null. So you can write your own check function
@Chrisir: we first need to establish where the json is coming from and if it has been parsed into a json object...
Thanks for answering. The error was my bad...
I provide the JSON from a client sketch.