-
-
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
support the Chinese language in json string #694
Comments
There is no attachment. The library does support UTF-8, so Chinese characters should not be a problem. Can you provide an example? |
{"authority":0,"category":6,"category_id":"0","delete_by":"","delete_time":"","ext":"","ext_link":0,"is_delete":0,"is_file":0,"is_share":0,"lv_creator":"","lv_id":1,"lv_size":0,"lv_time":"","name":"回收站","x_id":6,"x_pid":1} |
What is the error message and how does the code look like that produces this error message? |
error occured in the function get_token() when parse the Chinese string |
can you find my attachment in this topic, I didn't find it. |
This code works for me: #include <json.hpp>
#include <iostream>
using json = nlohmann::json;
int main()
{
std::string s = R"({"authority":1,"category":6,"category_id":"0","delete_by":"","delete_time":"","ext":"","ext_link":0,"is_delete":0,"is_file":0,"is_share":0,"lv_creator":"","lv_id":1,"lv_size":0,"lv_time":"","name":"回收站","x_id":6,"x_pid":1})";
json j = json::parse(s);
std::cout << std::setw(2) << j << std::endl;
} What is the error message and how does the code look like that produces this error message? |
test code is as below: |
Can you make sure the content of What is the error message? |
(You seem to copy the string from window text into a |
GetWindowTextW do not mean you get a utf8 encode string!! |
error message is:parse error - unexpected '"' on line 11615. |
Which Unicode? The library only supports UTF-8. |
@josephsmeng I convert CString to std::string by my funciton ToSTR, do you see it?
} |
@nlohmann you are just so nice, let the young man google his problem, and lean some thing about Unicode .... |
when I create a new project by VS2015, the default charset is Unicode. you can find it in VS as below |
"Unicode" describes a family of encodings. For this library, the string you pass to |
got it, thank you nlohmann. |
你可以从这里开始 http://www.ruanyifeng.com/blog/2007/10/ascii_unicode_and_utf-8.html, |
呵呵,我不喜欢在编码上浪费时间。 |
你高兴就好啦😄😄😄 |
this setting is not meaning your program character is UTF-8. It means the windows library function will use Unicode version funciton, such as SetWindowTextA() and SetWindowTextW(). When you use "Use Unicode Character Set", the unicode version function - SetWindowTextW will be call finally, not SetWindowTextA. |
老哥怎么解决中文的问题的?能说一下吗? |
不建议直接改代码,可以看看我之前在类似问题的解决方向:#1022 |
好的,谢谢老哥 |
In Qt project, you can use |
1、确保windows中源文件(visual studio中)都是utf-8 with bom格式; 综上,nlohmann在源码中应该考虑windows环境下输出到控制台时做U2G转换,不过考虑开源不易,期待有朋友提pr改一下~ |
The library only supports UTF-8. |
Yes, so let the users solve other encoding problems themselves ^.^ |
new version doesn't support the Chinese language in json string, I has been fixed. please see the attachment.
The text was updated successfully, but these errors were encountered: