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

About Serialization Error invalid UTF-8 byte at index #3414

Closed
2 tasks
TimelifeCzy opened this issue Apr 3, 2022 · 2 comments
Closed
2 tasks

About Serialization Error invalid UTF-8 byte at index #3414

TimelifeCzy opened this issue Apr 3, 2022 · 2 comments
Labels
solution: invalid the issue is not related to the library

Comments

@TimelifeCzy
Copy link

Description

Chinese deserialization error

Reproduction steps

#include <json.hpp>
using json_t = nlohmann::json;
std::string ch="中文";
json_t j;
j["ch_debug"]=ch.c_str();
j.dump();

Expected vs. actual results

try_

Minimal code example

#include <json.hpp>
using json_t = nlohmann::json;
std::string ch="中文";
json_t  j;
j["ch_debug"]=ch.c_str();
j.dump();

Error messages

JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + ss.str(), BasicJsonType()));

Compiler and operating system

win10 20he - IDE vs2019

Library version

3.10.5

Validation

TimelifeCzy added a commit to theSecHunter/Hades-Windows that referenced this issue Apr 3, 2022
rapidjson复用有些不熟悉,详细:
Tencent/rapidjson#2013
更替为nlohmann_json,但中文反序列化时候不友好utf8,详细:
nlohmann/json#3414
后续如果没有对应的api解决,将引入boost::uft8编码转换后在反序列化,所以数据只要是string都要处理,因为不知道是否有中文,否则序列化将抛出异常.
@nlohmann nlohmann removed the kind: bug label Apr 3, 2022
@nlohmann
Copy link
Owner

nlohmann commented Apr 3, 2022

@TimelifeCzy
Copy link
Author

TimelifeCzy commented Apr 3, 2022

thank OK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: invalid the issue is not related to the library
Projects
None yet
Development

No branches or pull requests

2 participants