-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Why quote for string when use StreamWriterBuilder? #894
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
Comments
@MeMeDa Do you mean |
em, may be my bad English made some errors. The right steps may be
while current json cpp is
|
Yes, you are right. #include <iconv.h>
//...
int SometypeToUTF8(const string& input, string& output, const string& type)
{
//...
iconv_t cd = iconv_open("utf-8",type); //decode the bytes to unicode according to right encoding (here GB18030)
//...
iconv(cd, &input, &InPutLen, &output, &OutPutLen); //output unicode code-point
//...
iconv_close(cd);
} |
Oh, I did it as you said. While I still can't understand why we should quote the bytes to unicode, instead of directly use the raw bytes. May be some standard? |
@MeMeDa Also, I made some tests for Chinese String, like
The actual result:
When I used StreamWriterBuilder to wirte, the result was same.
FastWriter didn't return the raw bytes when processing non-ascii characters. |
Thanks for keeping tracking. In the code you post, where
is the key point. The I know the best way currently is firstly translated other encoding to
to let the result keep raw-bytes. |
PR #1045 for emitUTF8 was merged. |
Uh oh!
There was an error while loading. Please reload this page.
Oh, It is nice to use
StreamWriterBuilder
and I can set the precision of float values.But, I found that all the Non-Ascii characters are quoted.
After dived into the source code, I found the
static String valueToQuotedStringN(const char* value, unsigned length)
, and it scared me: it try to quote non-ascii characters to unicode code-point according to the UTF8 rules, ignoring the actual String Encoding.I know in the document or somewhere, it says the jsoncpp only support UTF-8, but I think the brutally quote them are not proper methods. The original Api, like
FastWriter
, just return the raw bytes, Why not follow it?Or, we can follow the json lib of Python, like
that is, let us get the raw bytes by providing a settting.
The text was updated successfully, but these errors were encountered: