Convertion of special Characters into Json::Value

Sep 29, 2015 at 8:55 PM
Hi,
I'm new with Casablanca and I have some Problems to get a special Character into JSON. In this Example I want to convert a multidimensional Array containing std:string into a JSON Value.
json::value tab_to_json_array(vector< vector <string> > tab)
{
        auto answer = json::value::array();
    int count = 0;
    for (auto const & p : tab)
    {
        auto inner_vec = json::value::array();
        int inner_count = 0;
        for (auto const & p_inner : p){
        inner_vec[inner_count] = json::value(to_string_t(p_inner));
        inner_count++;
    }
        answer[count] = inner_vec;

        count++;
    }
            return answer;
}
It works fine, but when "p_inner" contains a "ß" for example, the to_string_t methods throws the following Exception:
Unhandled exception at 0x7735C42D in ConsoleApplication2.exe: Microsoft C++ exception: std::range_error at memory location 0x002CEF4C.

Has anyone an idea how to deal with special characters?
Oct 8, 2015 at 8:57 PM
hey arminaigner

to_string_t requires expects valid UTF-8 string as input. In your example above, I believe p_inner is not UTF-8.
One way to approach this would be to convert the input string to UTF-8. You can write some helper to acheive this, please refer to this discussion for an example.

Thanks
Kavya.