Skip to content
This repository has been archived by the owner on Oct 13, 2022. It is now read-only.

No way to check if an entry in the JSON actually exists. #6

Open
abledbody opened this issue May 2, 2022 · 1 comment
Open

No way to check if an entry in the JSON actually exists. #6

abledbody opened this issue May 2, 2022 · 1 comment

Comments

@abledbody
Copy link

Say you have a JSON that looks like this:
{ "someThing": { "fieldA": 10.0, "fieldC": 5.0 } }
And some code that looks like this:
var fieldB = json["someThing"]["fieldB"]
There's no way to check if you successfully found an entry in that spot. If you try and access the value, float fieldBValue = fieldB it will simply fail an assertion.
I recommend changing most of the assertions in Json class to exceptions, so that they can be caught and handled by the user of the API.

@abledbody abledbody changed the title No way to check if the entry in the JSON actually exists. No way to check if an entry in the JSON actually exists. May 2, 2022
@abledbody
Copy link
Author

Also, adding a new entry in the internal dictionary every time you can't find a key is an extremely bad idea, because it allocates more memory for an action that shouldn't even (noticeably) mutate the class. This should also be an exception.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant