Json: error parse

Created on 15 Mar 2019  Β·  14Comments  Β·  Source: nlohmann/json

{"Code":1,"Message":"η”¨ζˆ·η™»ε½•ζˆεŠŸ","Data":{"Token":"146A307B82184AB5A00918CF9B612160","User":{"UserId":"3cd1cd06-3d77-4efb-a78d-ad9a9cea3d80","RealName":"admin","Department":"ζ΅‹θ―•1"},"Settings":null},"PageIndex":null,"PageSize":null,"TotalCount":null,"TotalPageCount":null}

this json str can't parse through

question visual studio wontfix

Most helpful comment

i like your lib very much, it's Intuitive , and simple. but if it do not support gbk, i feel sad, and use rapidjson(china tencent) insead of nlohmann. i think in the world (in win32) , there are many other program run in code page that is not utf8.

All 14 comments

with gbk, chinese

json throw JSON_THROW(*static_cast(&ex));

The JSON above is indeed valid and the following program works:

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

using json = nlohmann::json;

int main() {
    json j = R"({"Code":1,"Message":"η”¨ζˆ·η™»ε½•ζˆεŠŸ","Data":{"Token":"146A307B82184AB5A00918CF9B612160","User":{"UserId":"3cd1cd06-3d77-4efb-a78d-ad9a9cea3d80","RealName":"admin","Department":"ζ΅‹θ―•1"},"Settings":null},"PageIndex":null,"PageSize":null,"TotalCount":null,"TotalPageCount":null})"_json;

    std::cout << j.dump(2) << std::endl;
}

The library does only support UTF-8 though. Other encodings are not supported. The error may come from a misinterpretation of GBK.

thank, but in my point, the gbk and utf8 or other codepage, the ascii part is same, the process of interpretation should not mistake. just like tinyxml2, it work well with gbk or utf8.

But your value does not only contain ASCII values. For this library, it makes a difference whether η”¨ζˆ·η™»ε½•ζˆεŠŸ is encoded as UTF-8 or GBK.

00-7F 0xxx xxxx //ascii and gbk, utf8 same
07-FF 110x xxxx 10xx xxxx
...

what i want voice is that, if any char first bit is 1, you shoud process it as text, and do need to interpretate it, what we interest and need to interpretate is the char value below 128(unsinged)

if a str is abc , so it is 0xxx xxxx, 0xxx xxxx, 0xxx xxxx
if b str is aδΈ­c, so it is 0xxx xxxx, 1xxx xxxx, 1xxx, xxxx, 0xxx xxxx, whether in gbk or utf8

Could you please attach the above JSON as file, so I can check myself?

ok, wait half hours

[email protected]:ChinaCCF/TestJSON.git

the file commit here, and i recheck again, the same error

Thanks! Here is the error message I get:

libc++abi.dylib: terminating with uncaught exception of type nlohmann::detail::parse_error: [json.exception.parse_error.101] parse error at line 1, column 23: syntax error while parsing value - invalid string: ill-formed UTF-8 byte; last read: '"\323\303'

And indeed, the string η”¨ζˆ·η™»ε½•ζˆεŠŸ begins at column 28. The parser complains about the byte sequence 0323 0303 (octal) which is 0xD3 0xC3 (hex). In UTF-8, D3 indicates the start of a 2-byte sequence. The next byte must be in the range 0x80..0xBF. Therefore, 0xC3 is unexpected here.

This library does not support any other encoding but UTF-8. The encoding of η”¨ζˆ·η™»ε½•ζˆεŠŸ in GBK is invalid UTF-8, so it is rejected by the library.

i like your lib very much, it's Intuitive , and simple. but if it do not support gbk, i feel sad, and use rapidjson(china tencent) insead of nlohmann. i think in the world (in win32) , there are many other program run in code page that is not utf8.

Sorry to hear that.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

moneroexamples picture moneroexamples  Β·  4Comments

mlund picture mlund  Β·  4Comments

MariaRamos89 picture MariaRamos89  Β·  4Comments

jmlemetayer picture jmlemetayer  Β·  3Comments

zhishupp picture zhishupp  Β·  4Comments