json icon indicating copy to clipboard operation
json copied to clipboard

[json.exception.type_error.316] invalid UTF-8 byte at index 0: 0xB6

Open zhjiarong opened this issue 3 years ago • 1 comments

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: image REPLY.bson:有中文 image 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

zhjiarong avatar Dec 14 '22 08:12 zhjiarong

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?

nlohmann avatar Dec 14 '22 09:12 nlohmann

@zhjr2019 Any update?

nlohmann avatar Feb 20 '23 07:02 nlohmann

@nlohmann I don't know how to modify it. Can you teach me?

zhjiarong avatar Oct 07 '23 13:10 zhjiarong