Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

has_key? #12

Closed
MYeager1967 opened this issue Aug 24, 2014 · 7 comments
Closed

has_key? #12

MYeager1967 opened this issue Aug 24, 2014 · 7 comments
Labels

Comments

@MYeager1967
Copy link

Is there a reliable method of checking to see if the JSON data contains a given key? The methods I'm trying are all failing horribly and I'm sure it's my fault.

@bblanchon
Copy link
Owner

Both Generator::JsonObject and Parser::JsonObject have the following public method:

bool containsKey(const char* key);

which returns true if the key is present, and false if not.

@MYeager1967
Copy link
Author

I'll give this a look when I get back to my computer. If i can figure out
how to make it work, it will greatly ease my coding burden on this
project. Is there any full documentation on this library? I like it's
footprint over aJSON...
On Aug 25, 2014 2:39 AM, "Benoît Blanchon" notifications@github.com wrote:

Both Generator::JsonObject and Parser::JsonObject have the following
public method:

bool containsKey(const char* key);

which returns true if the key is present, and false if not.


Reply to this email directly or view it on GitHub
#12 (comment)
.

@MYeager1967
Copy link
Author

I believe I have it figured out. I haven’t actually run the code yet but the line:

bool containsKey(const char* Pool);

seems to pass the verify built into the IDE. No guarantee it will do what I want it to do though. Is it possible to check for a nested key or do I need to check for the first key (Pool in this case) and then check for subkeys under it? I realize this is an Arduino library and code space is a premium. I’m just ecstatic to have a library to handle JSON that doesn’t eat up too much memory.

Mike

From: Benoît Blanchon [mailto:notifications@github.com]
Sent: Monday, August 25, 2014 2:39 AM
To: bblanchon/ArduinoJson
Cc: MYeager1967
Subject: Re: [ArduinoJson] has_key? (#12)

Both Generator::JsonObject and Parser::JsonObject have the following public method:

bool containsKey(const char* key);

which returns true if the key is present, and false if not.


Reply to this email directly or view it on GitHub #12 (comment) .

@MYeager1967
Copy link
Author

Ok. It didn’t do what I expected….

From: Benoît Blanchon [mailto:notifications@github.com]
Sent: Monday, August 25, 2014 2:39 AM
To: bblanchon/ArduinoJson
Cc: MYeager1967
Subject: Re: [ArduinoJson] has_key? (#12)

Both Generator::JsonObject and Parser::JsonObject have the following public method:

bool containsKey(const char* key);

which returns true if the key is present, and false if not.


Reply to this email directly or view it on GitHub #12 (comment) .

@MYeager1967
Copy link
Author

Ok. With a little time to think and pull my head out of my ass, I figured it out. Thank you for not replying too quick with an answer… I’d still like to know if it’s possible to check for nested keys without testing at multiple levels. Like I said, if not, it’s no big deal. My life is already easier….

From: Benoît Blanchon [mailto:notifications@github.com]
Sent: Monday, August 25, 2014 9:39 AM
To: bblanchon/ArduinoJson
Cc: MYeager1967
Subject: Re: [ArduinoJson] has_key? (#12)

Please have a look at the README files:
https://github.com/bblanchon/ArduinoJson/blob/master/README.md
https://github.com/bblanchon/ArduinoJson/blob/master/JsonGenerator/README.md
https://github.com/bblanchon/ArduinoJson/blob/master/JsonParser/README.md


Reply to this email directly or view it on GitHub #12 (comment) .

@bblanchon
Copy link
Owner

You could just try to get the value and see if it exists.
Like this:

json["key1"]["key2"].success()

Repository owner locked and limited conversation to collaborators Sep 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants