-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Chinese character initialize error #2325
Comments
Please make sure the file is UTF-8 encoded. |
I solve it ok now. Thanks. |
请问老哥 咋解决的?俺这个代码也是utf-8的,但是中文乱码了呀 |
老哥怎么解决中文的问题的? |
English, please. We can't help you if we can't understand you. Answering your translated question… Either make sure your source file is UTF-8 encoded or use json j = json::parse(u8"JSON string with Chinese characters");
// or
json j = json::parse(u8 R"(JSON string with Chinese characters)"); |
finally I solve this problemOther UTF8 characters such as Russian, Greek and special symbols also can be displayed correctly. Features:
tutorial:step 1visual studio set source and execution character sets to UTF-8 step 2visual studio menu - file - Advanced Save Options - set "UNICODE(UTF-8 with BOM) - 65001" step 3add code at top of Main(). This will display UTF8 correctly.
this is my utf-8 json test code.
|
FYI: An UTF-8 BOM is ignored by the library - you don't need to remove it. |
honestly I don't know how to set the BOM. When Visual Studio Compiler command with not |
If it works, then everything is fine. |
Chinese character initialize error
What is the issue you have?
#[error info]:
[json.exception.parse_error.101] parse error at line 3, column 14: syntax error while parsing value - invalid string: ill-formed UTF-8 byte; last read: '"中'
Please describe the steps to reproduce the issue.
1.build ok
2.run error.
3.
Can you provide a small but working code example?
What is the expected behavior?
Normal parse
And what is the actual behavior instead?
con_json["aaa"] = "张三";//this is ok
auto jsonStr1 = "{"name": "中国", "happy": true, "pi": 3.141 }"_json; // this is error
auto jsonStr2 = R"(
{
"name": "中国",
"happy": true,
"pi": 3.141
}
)"_json;// this is error also
Which compiler and operating system are you using?
Which version of the library did you use?
develop
branchIf you experience a compilation error: can you [compile and run the unit tests]
The text was updated successfully, but these errors were encountered: