JsonCPP Handling Unicode Key and Values

I am going to use non-ASCII characters as key in Json. Consider following example:

   "सर्वज्ञ पन्त.txt":"1234"

which is valid according to this site.

Now I would like to use this sample in my JSONCPP code. Consider

#include <iostream>
#include <fstream>
#include <jsonwriter.h>
#include <jsonreader.h>

int main()
    Json::Value root;
    Json::StyledStreamWriter writer;
    Json::Reader reader;
    std::string json = "{"type":"net.aggregate","post.source":"1209010340", "val":1000}";
    bool success = reader.parse(json,root);
        std::cout << root << std::endl;
    std::cout << root["post.source"] << std::endl;
    root["post.source"] = "12345678";
    std::cout << root << std::endl;
    std::ofstream file;
    writer.write(file, root);
    return 0;

The above code works fine when the key are non-unicode. I could add the key सर्वज्ञ पन्त.txt as root["सर्वज्ञ पन्त.txt"] = "1234", but this shows ???? when cout and also on file asdf.json.

How should I handle non-ascii characters? I would like to save those non-ascii characters as key/value and perform some sort of CRUD on them. Thank you..

Source: c++

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.