Are there any examples of how to iterate over keys and values of a JSON object?
I have tried this:
// iterate over the keys
J* key;
JObjectForEach(name, cmd.params) {
const char* keyname = JGetStringValue(key);
J* value = JGetObjectItem(cmd.params, keyname);
...
}
However, this doesn’t work, since const char* key = JGetStringValue(name);
returns nullptr
. This is because JGetStringValue is expecting (as you might guess from the name) a string value.
Internally, the J
struct has a stringvalue
pointer for true string values, and string
for key names.
I could just use key->string
to get the key name, but this is going behind the scenes. Is there an officially supported way to do this?