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

Error with non existing key #1981

Closed
AlejandroCastillejo opened this issue Mar 11, 2020 · 3 comments
Closed

Error with non existing key #1981

AlejandroCastillejo opened this issue Mar 11, 2020 · 3 comments
Labels
kind: question state: needs more info the author of the issue needs to provide more details

Comments

@AlejandroCastillejo
Copy link

  • I am trying to read a value in a json file but I cannot be sure that the variable exists in the file.

  • When I try to get the value of a non existing key it comes with an error and the program shuts down.
    I wonder if there if any way to check if a variable with this key exists in the file before reading it. So this way I could avoid he error.

Thank you for your help

@t-b
Copy link
Contributor

t-b commented Mar 11, 2020

@AlejandroCastillejo The contains method should do the trick, see https://nlohmann.github.io/json/classnlohmann_1_1basic__json_a9286acdc0578fc66e9346323e69fc0e3.html#a9286acdc0578fc66e9346323e69fc0e3.

@AlejandroCastillejo
Copy link
Author

Thank you for your response.
Now there is another Issue since I changed to the last version of the single include file.
When I try to compile, there are some error messages like this:
error: redefinition of ‘class nlohmann::json_pointer’
class json_pointer

Before I was using version 3.1.2. I updated it because this previous version does not include the 'contains' method.

Thanks again for your help.

@nlohmann
Copy link
Owner

In order to asses your issue, we need the following information:

  • What is the issue you have?

  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?

  • What is the expected behavior?

  • And what is the actual behavior instead?

  • Which compiler and operating system are you using? Is it a supported compiler?

  • Did you use a released version of the library or the version from the develop branch?

  • If you experience a compilation error: can you compile and run the unit tests?

@nlohmann nlohmann added the state: needs more info the author of the issue needs to provide more details label Mar 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question state: needs more info the author of the issue needs to provide more details
Projects
None yet
Development

No branches or pull requests

3 participants