Chinese parsing bug of JsonAPI in the Haxe standard library

Source: Internet
Author: User
Currently, Json text needs to be parsed in Haxe. There are two third-party libraries related to Json in haxelib, but they have not been updated for a long time. After Haxe2.1, jsonAPI has become part of the standard library, specifically haxe. json class. Currently, I only use parsing, and it is very simple to use... syntaxHighlighter. al currently needs to parse Json text in Haxe. There are two Json-related third-party libraries in haxelib, but they have not been updated for a long time. Since Haxe 2.1, json APIs have become part of the standard library, specifically haxe. json class. Currently, I only use parsing and it is easy to use. Json. parse (jsonText: String) can be called to parse Json text into a Dynamic object. Supports Boolean, integer, floating point, String, array, composite object, and other data types. Note that attribute names must also be enclosed by double quotation marks. Otherwise, they cannot be parsed. In the following example, the double quotation marks outside uid and name cannot be omitted: www.2cto.com {"uid ": 12345, "name": "Rocks Wang"} in the Flash target, the runtime string encoding is Unicode, so there is no problem with Chinese. I will not go into details here. In the cpp target, the character string is actually a char * in C ++ at runtime. Therefore, Chinese encoding requires special attention. Haxe and NME in Chinese processing is not bad, in most cases, as long as the use of UTF-8 encoding, Chinese can be normal analysis and display. Json API is the same, as long as the jsonText parameter in Json. parse (jsonText: String) is encoded in UTF-8, it can parse the Json text that contains Chinese characters. However, in actual use, it is found that errors occur frequently in Chinese Parsing. After source code analysis, it is determined that a Bug exists in the Json class. The specific correction is as follows: Row 321, before modification: else if (c> = 0x80) {pos ++; // here, one more character is skipped, because nextChar itself needs to skip one character if (c> = 0xE0) pos + = 1 + (c & 32); // determines whether to skip one character based on the 5th-bit length. For details, see the UTF-8 encoding specification after correction: else if (c> = 0x80) {pos + = 1 + (c & 32)> 5); after this correction, json class can parse Json text data containing Chinese characters perfectly.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.