-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Add something like Json::StaticString #1402
Comments
I do not see why such a string would be faster. Can you elaborate? |
It seems to be useful when adding fields with same name to an JSON object:
http://open-source-parsers.github.io/jsoncpp-docs/doxygen/class_json_1_1_static_string.html#details I assume the optimization just happens here: static const Json::StaticString JsonStringFoo{ "foo" };
Json::Value data1;
Json::Value data2;
data1[JsonStringFoo] = 111;
data2[JsonStringFoo] = 222; // <-- here the "foo" string is not duplicated internally. |
(and also when storing the same string as value). |
When you pass a string to |
Understood. May I ask which would be the proper way to check whether a key exists, check its type is the desired one and read the corresponding type value into a C++ variable (without looking for the given key 3 times into the internal |
You can use |
Do you mean using the |
I’m not sure what you mean. Can you provide an example? |
Sure. In libsdptransform (in which I use auto h264Fmtp = sdptransform::parseParams(video.at("fmtp")[0].at("config"));
std::string profileLevelId;
if (
h264Fmtp.find("profile-level-id") != h264Fmtp.end() &&
h264Fmtp["profile-level-id"].is_string()
)
{
profileLevelId = h264Fmtp.at("profile-level-id");
} In this usage example, I'm forcing |
Once you make sure the iterator is not end(), you can dereference it to a reference where you can call all member functions. |
I wonder if I could do something like: auto h264Fmtp = sdptransform::parseParams(video.at("fmtp")[0].at("config"));
std::string profileLevelId;
// Iterator
auto it = h264Fmtp.find("profile-level-id");
// Pseudo code here:
if (it != h264Fmtp.end() && it->second.is_string())
profileLevelId = it->second.get<std::string>(); |
oh, so it would be: auto h264Fmtp = sdptransform::parseParams(video.at("fmtp")[0].at("config"));
std::string profileLevelId;
// Iterator
auto it = h264Fmtp.find("profile-level-id");
// Pseudo code here:
if (it != h264Fmtp.end() && it->is_string())
profileLevelId = it->get<std::string>(); Am I right? |
...or just: profileLevelId = *it; |
And this is properly documented in the API, so let's close this issue. Thanks :) |
In JsonCpp I can create a "static" JSON string to be used as a Object key with fast access.
The thing here is that
data[JsonStringFoo]
is supposed to be much faster than usingdata["foo"]
all the time.AFAIS
nlohmann/json
does not provide something like that, although it may provide a different approach to get the same result.The text was updated successfully, but these errors were encountered: