-
-
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
error parsing character å #1626
Comments
This library does supports UTF-8, even with If that string is a string literal hardcoded in the source code file, you might want to make sure your source code file encoding is in UTF-8. If you are reading it from a file, check the encoding of that file and make sure it is UTF-8. |
char mess[3000]="{"machine.serialnumber":"G4åd"}"; std::string s = mess; bool validated = nlohmann::json::accept(s); nlohmann::json::parse(s); This is the code that produces exception. |
Shouldn't you skip the double-quotes (e.g. by putting Also, you should probably make sure your source file is being saved in UTF-8 encoding, not some others (e.g. ASCII, UTF-16). To be able to easier to track down the issue, you can test the following code. Put the JSON in a separate file named #include <fstream>
#include <sstream>
#include <string>
#include <iostream>
#include "json.hpp"
using namespace std;
int main()
{
std::ifstream fin("input.json");
if(!fin)
{
cout << "Failed to open file." << endl;
return 1;
}
std::stringstream stream;
stream << fin.rdbuf();
std::string json_string = stream.str();
cout << "File contents:" << endl;
cout << json_string << endl << endl;
bool validated = nlohmann::json::accept(json_string);
cout << "Json validation result: " << validated << endl;
auto json = nlohmann::json::parse(json_string);
cout << "machine.serialnumber: " << json["machine.serialnumber"] << endl;
return 0;
} I have tested it and it outputs the following as expected:
If this solved your issue, you should compare the string you had in your code to |
@mikelaltadi Do you need further assistance? |
No. I replace this letter by ‘a’ when I find it before parsing. Its enough for me. Thanks. |
Hello!
Im having a trouble parsing a std::string that contains this character. å
I see it with decimal value of -27 in a array of chars.
And the nlohmann::json::accept
and
nlohmann::json::parse function
gives me an error
error_message = "invalid string: ill-formed UTF-8 byte";
But, if the character is in a std::string , should be valid isn´t it?
Environment: Windows 10 and Microsoft Visual Studio 2015
In this page, that validates UTF-8 , says that å is a correct UTF-8 character.
https://onlineutf8tools.com/validate-utf8
The text was updated successfully, but these errors were encountered: