Skip to content

Chinese character initialize error #2325

@xingyun86

Description

@xingyun86

Chinese character initialize error

What is the issue you have?

//main.cpp encode=utf8
int main(int argc, char ** argv)
{
	std::cout << "Hello CMake." << std::endl;
	setlocale(LC_ALL, "chs");
	try
	{
		// create object from string literal
		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**
		{
			json con_json;
			con_json["aaa"] = "张三";//**this is ok**
			std::cout << con_json.dump() << std::endl;
		}
         } catch (const std::exception& e)
        {
              std::cout << e.what() << std::endl;
        }
}

#[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?

  • Compiler: msvc_vs2019
  • Operating system: win10v2004_

Which version of the library did you use?

  • [ x] latest release version 3.9.0
  • other release - please state the version: ___
  • the develop branch

If you experience a compilation error: can you [compile and run the unit tests]

  • yes
  • [ x] no - please copy/paste the error message below

Metadata

Metadata

Assignees

No one assigned

    Labels

    solution: invalidthe issue is not related to the librarysolution: proposed fixa fix for the issue has been proposed and waits for confirmation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions