Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 of 2 tasks
zhjr2019 opened this issue Dec 14, 2022 · 3 comments
Closed
1 of 2 tasks

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

zhjr2019 opened this issue Dec 14, 2022 · 3 comments
Labels
aspect: binary formats BSON, CBOR, MessagePack, UBJSON kind: bug state: needs more info the author of the issue needs to provide more details

Comments

@zhjr2019
Copy link

zhjr2019 commented Dec 14, 2022

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

@nlohmann
Copy link
Owner

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 nlohmann added aspect: binary formats BSON, CBOR, MessagePack, UBJSON state: needs more info the author of the issue needs to provide more details labels Dec 14, 2022
@nlohmann
Copy link
Owner

@zhjr2019 Any update?

@nlohmann nlohmann closed this as not planned Won't fix, can't repro, duplicate, stale Mar 5, 2023
@zhjr2019
Copy link
Author

zhjr2019 commented Oct 7, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aspect: binary formats BSON, CBOR, MessagePack, UBJSON kind: bug state: needs more info the author of the issue needs to provide more details
Projects
None yet
Development

No branches or pull requests

2 participants