You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The C++ wrapper is great, but I'm missing one thing: a way to loop through array in a c++ fool-proof way. I know that I can do this:
json_value arr = (*settings)["web_server"]["cgi_extensions"];
if (arr.type == json_array) {
int length = arr.u.array.length;
for (int i = 0; i < length; i++) {
...
}
}
But, a newbie might forget the type checking and just go with:
json_value arr = (*settings)["web_server"]["cgi_extensions"];
int length = arr.u.array.length;
for (int i = 0; i < length; i++) {
...
}
If someone makes a mistake in the json file, so that array is missing or becomes a string, then this code will crash the application.
I love the C++ wrapper mostly that it is fool-proof, I can reference to a non-existing key and it just returns an empty string, I will mistake the types and it will just return 0, nothing bad happens. But when it comes to looping through arrays it's easy to make a mistake, I've done it already and I'm a little scared of writing such code.
What I'm looking for is some method like GetArrayLength() that will return array length or 0 when value is not an array.
Czarek.
The text was updated successfully, but these errors were encountered:
I added support for C++11 range-based for-loops in #21 but I wasn't able to make it do a type check because of the nested class structure preventing access to the type member variable. If I could somehow access type, I could return nullptr for both begin and end for the wrong type, thus not looping at all, but I don't know how to access type.
Hi,
The C++ wrapper is great, but I'm missing one thing: a way to loop through array in a c++ fool-proof way. I know that I can do this:
But, a newbie might forget the type checking and just go with:
If someone makes a mistake in the json file, so that array is missing or becomes a string, then this code will crash the application.
I love the C++ wrapper mostly that it is fool-proof, I can reference to a non-existing key and it just returns an empty string, I will mistake the types and it will just return 0, nothing bad happens. But when it comes to looping through arrays it's easy to make a mistake, I've done it already and I'm a little scared of writing such code.
What I'm looking for is some method like GetArrayLength() that will return array length or 0 when value is not an array.
Czarek.
The text was updated successfully, but these errors were encountered: