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
While developing a webserver, I discovered that JSON and maps have a lot in common. To be more specific, a key-value pair, where the key is used to retrieve the corresponding value. In addition, it is syntactically similar as well, e.g.,
Please consider adding a feature to convert a std::map/unordered_map to a JSONVar. This feature could be used in many cases, e.g., serialise user information, file information and device information to be stored in a file or sent across the Internet. Thank you.
The text was updated successfully, but these errors were encountered:
It is important to acknowledge that not all datatypes are supported. For example, std::unordered_map<String, struct> is rather difficult to be converted to JSON object. For multidimensional maps of supported types, the library could convert it into a multi-level JSON, i.e., std::unordered_map<String, std::unordered_map<String, int>> ==> JSONVar["xxx"][n].
std::unordered_map<String, int> my_umap; // create an unordered_map
JSONVar my_JSON_obj; // create instance of JSONVar
my_JSON_obj = JSON.parse(my_umap); // parse unordered_map to JSON object
JSON.stringify(my_JSON_obj); // output JSON string
As for the implementation part, it could be done by recursively traversing the map until all layers are accessed. It may also be done iteratively if possible.
While developing a webserver, I discovered that JSON and maps have a lot in common. To be more specific, a key-value pair, where the key is used to retrieve the corresponding value. In addition, it is syntactically similar as well, e.g.,
Please consider adding a feature to convert a std::map/unordered_map to a JSONVar. This feature could be used in many cases, e.g., serialise user information, file information and device information to be stored in a file or sent across the Internet. Thank you.
The text was updated successfully, but these errors were encountered: