json
json copied to clipboard
[json.exception.type_error.316] invalid UTF-8 byte at index 0: 0xB6
Description
int main()
{
try
{
std::ifstream replyfile("D:\\REPLY.bson", std::ios::in | std::ios::binary);
if (!replyfile.is_open())
{
return EXIT_FAILURE;
}
std::istreambuf_iterator<char> beg(replyfile), end;
std::string replycontent = std::string(beg, end);
replyfile.seekg(0, std::ios::end);
nlohmann::json replyjson = nlohmann::json::from_bson(replycontent);
std::cout << replyjson << std::endl;
replyfile.close();
}
catch (std::exception& e)
{
std::cout << e.what() << std::endl;
}
system("pause");
return 0;
}
output:
REPLY.bson:有中文
REPLY.bson file:
REPLY.zip
Reproduction steps
打开包含中文字符的bson文件。
Expected vs. actual results
能正确读写包含中文字符的bson文件。
Minimal code example
No response
Error messages
[json.exception.type_error.316] invalid UTF-8 byte at index 0: 0xB6
Compiler and operating system
windows11
Library version
3.11.2
Validation
- [ ] The bug also occurs if the latest version from the
developbranch is used. - [X] I can successfully compile and run the unit tests.
There is an error and index 0 which means already the first byte is invalid. The spec (https://bsonspec.org/spec.html) does not allow byte 0xB6 as first byte.
When I look at your file, the first byte is 0x6E, however. Can you please double check your example?
@zhjr2019 Any update?
@nlohmann I don't know how to modify it. Can you teach me?