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

Found a bug! #154

Closed
shu7734 opened this issue Feb 23, 2021 · 13 comments
Closed

Found a bug! #154

shu7734 opened this issue Feb 23, 2021 · 13 comments

Comments

@shu7734
Copy link

shu7734 commented Feb 23, 2021

STREQ(json_object_get_string(root_object, "utf string"), "lorem ipsum中华人2民共和国")- FAIL
STREQ(json_object_get_string(root_object, "utf-8 string"), "中国あいうえお")- FAIL

@kgabis
Copy link
Owner

kgabis commented Feb 23, 2021

Did you just change code in tests.c without changing files used for those tests?
Please provide a way of reproducing this "bug".

@shu7734
Copy link
Author

shu7734 commented Feb 23, 2021

I just changed test.c

TEST(json_object_set_string(obj, "utf string", "lorem ipsum中华人2民共和国") == JSONSuccess);
TEST(json_object_set_string(obj, "utf-8 string", "あい中国うえお") == JSONSuccess);

@kgabis
Copy link
Owner

kgabis commented Feb 23, 2021

You need to change tests/test_2.txt and tests/test_2_comments.txt as well.

@shu7734
Copy link
Author

shu7734 commented Feb 23, 2021

Thank You

Is Work now!
But json_object_set_string not work in VS2019 when used "中华人民共和国" or any chinese word。
code:

JSON_Value *root_value = json_value_init_object();
JSON_Object *root_object = json_value_get_object(root_value);
char *serialized_string = NULL;
json_object_set_string(root_object, "name", "中华人民共和国");
json_object_set_number(root_object, "age", 25);
serialized_string = json_serialize_to_string(root_value);
printf(serialized_string);
json_free_serialized_string(serialized_string);
json_value_free(root_value);

@kgabis
Copy link
Owner

kgabis commented Feb 23, 2021

Is your source file encoded using utf8?

@shu7734
Copy link
Author

shu7734 commented Feb 23, 2021

is Worked from cJson+VS2019

char* name = "中华人2民共和国";
cJSON* objjson = cJSON_CreateObject();
cJSON_AddNumberToObject(objjson, "code", 120);
cJSON_AddStringToObject(objjson, "data", name);
char* serialized_string = cJSON_Print(objjson);

printf(serialized_string);

@shu7734
Copy link
Author

shu7734 commented Feb 23, 2021

No,encoded used gb2312

@shu7734
Copy link
Author

shu7734 commented Feb 23, 2021

cpp file encoded gb2312

@kgabis
Copy link
Owner

kgabis commented Feb 23, 2021

Please change it to utf-8, it should help.

@shu7734
Copy link
Author

shu7734 commented Feb 23, 2021

Thank You! I'll give it a try

@shu7734
Copy link
Author

shu7734 commented Feb 23, 2021

if I receved chinese word from network,I need change to UTF-8?

@kgabis
Copy link
Owner

kgabis commented Feb 23, 2021

gb2312 is a subset of unicode so it should work.

Does your example work after changing
json_object_set_string(root_object, "name", "中华人民共和国");
to
json_object_set_string(root_object, "name", u8"中华人民共和国");
?

@kgabis
Copy link
Owner

kgabis commented Feb 24, 2021

I'm closing this issue since it seems to be a problem in your setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants