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

Parsing the unicode string got the wrong result #4272

Open
2 tasks done
pigLoveRabbit520 opened this issue Jan 23, 2024 · 7 comments
Open
2 tasks done

Parsing the unicode string got the wrong result #4272

pigLoveRabbit520 opened this issue Jan 23, 2024 · 7 comments
Labels
solution: invalid the issue is not related to the library

Comments

@pigLoveRabbit520
Copy link

Description

unicode string "\u7ec4" should get "组" but got "缁"

Reproduction steps

copy latest json.hpp to vs C++ project and write the code below.

Expected vs. actual results

should get but got

image

Minimal code example

#include <fstream>
#include <iostream>
#include "json.hpp"

using json = nlohmann::json;

int main()
{
	std::ifstream f("data.json");
	json data = json::parse(f);
	std::string name = data.at("name");
	std::cout << name << std::endl;
	return 0;
}

json data

{
  "name" : "\u7ec4"
}


### Error messages

```Shell
no error

Compiler and operating system

vs 2022 and windows 11

Library version

version 3.11.3

Validation

@nlohmann
Copy link
Owner

image

I cannot reproduce this.

@pigLoveRabbit520
Copy link
Author

On Linux I also got the right answer. but I am using Windows and visual studio.
On windows I got the wrong answer.

@nlohmann
Copy link
Owner

Can you show the output of data.dump(-1, ' ', true)? This should show \u7ec4, but I want to be sure.

@syoyo
Copy link

syoyo commented Jan 27, 2024

@pigLoveRabbit520 Confirmed its an issue of your Console codepage. You are using cp936(Simplified Chinese). It prints 组 as 缁. chcp 65001(UTF8) should print 组 as 组. So its not the issue of nlomann json.

@nlohmann nlohmann added solution: invalid the issue is not related to the library and removed kind: bug labels Jan 28, 2024
@pigLoveRabbit520
Copy link
Author

@syoyo I have changed the codepage to 65001, however, I got the wrong result
image

@nlohmann nlohmann reopened this Jan 29, 2024
@nlohmann
Copy link
Owner

Please check my previous comment and post the output of dump

@nlohmann
Copy link
Owner

(And since I'm neither familiar with Chinese nor Windows - could there be an issue with the font?)

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

3 participants