-
-
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
Convenient way to make 'basic_json' accept 'QString' as an key type as well? #1640
Comments
I haven't tested this but how about overriding the using my_json_type = nlohmann::basic_json<std::map, std::vector, QString>;
my_json_type json;
QString key = "hello";
json[key] = "world"; I am not sure if |
Unfortunately when I tried that: // {...}
template<class K, class V, class dummyCompare, class A>
using nljson_fifo_map = nlohmann::fifo_map<K, V, nlohmann::fifo_map_compare<K>, A>;
//using nljson = nlohmann::basic_json<nljson_fifo_map>;
using nljson = nlohmann::basic_json<nljson_fifo_map, std::vector, QString>;
// {...} the result was this compilation error (MSVC 2015 64-Bit):
so at least the hash-thing is missing. Are there any chances to provide this hash? |
I am also afraid that if I use The Readme states about string encodings:
|
This solution might work. I gave
Option 2 is a faster and less hassle solution if you can minimize the instances where you have to modify/query the JSON object. But if there are many places that you have to do this conversion, Option 1 might worth trying as it encapsulates all those conversions in one place and would be easier to maintain. |
I agree with #1640 (comment). The library only has superficial support for other string types, especially if they do not have the API of |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I want to use Qt's
QString
type with the excellentnlohmann::json
.This works very well by providing the functions
to_json
andfrom_json
as described in the readme:nljson.h
nljson.cpp
However, I would find it very beneficial if it were possible to use
QString
as a key data type as well:myfile.cpp
Is there a convenient way to make
nlohmann::json
acceptQString
as a key type without this explicit conversion (baz.toStdString()
)?The text was updated successfully, but these errors were encountered: