json parser using nlohmann throws exception for Japanese characters

126 Views Asked by At

throws error json.hpp

case UTF8_REJECT:  // decode found invalid UTF-8 byte
                {
                    switch (error_handler)
                    {
                        case error_handler_t::strict:
                        {
                            JSON_THROW(type_error::create(316, concat("invalid UTF-8 byte at index ", std::to_string(i), ": 0x", hex_bytes(byte | 0)), nullptr));
                        }

                        case error_handler_t::ignore:

with exception

Microsoft C++ exception: nlohmann::json_abi_v3_11_2::detail::type_error

Code tried is as below , trying to add japanese characters

    std::ifstream ifs( _T("test.json" ));
    nlohmann::json jf = nlohmann::json::parse( ifs );
jf["qAaewEntry"]["IssueID]"] = "試験";
    std::ofstream ofs( _T( "test.json" ) );
    ofs << jf.dump( 4 );
    ofs.close();
 std::ifstream ifs( _T("test.json" ));
    nlohmann::json jf = nlohmann::json::parse( ifs );
jf["qAaewEntry"]["IssueID]"] = "試験";
    std::ofstream ofs( _T( "test.json" ) );
    ofs << jf.dump( 4 );
    ofs.close();
0

There are 0 best solutions below