diff --git a/src/main/java/org/redkale/convert/json/JsonByteBufferReader.java b/src/main/java/org/redkale/convert/json/JsonByteBufferReader.java index 8482f91d7..1717605b5 100644 --- a/src/main/java/org/redkale/convert/json/JsonByteBufferReader.java +++ b/src/main/java/org/redkale/convert/json/JsonByteBufferReader.java @@ -76,7 +76,7 @@ public class JsonByteBufferReader extends JsonReader { this.cacheChar = 0; return ch; } - + byte b = nextByte(); if (b >= 0) { // 1 byte, 7 bits: 0xxxxxxx return (char) b; diff --git a/src/main/java/org/redkale/convert/json/JsonReader.java b/src/main/java/org/redkale/convert/json/JsonReader.java index cb82a6133..3a107635f 100644 --- a/src/main/java/org/redkale/convert/json/JsonReader.java +++ b/src/main/java/org/redkale/convert/json/JsonReader.java @@ -180,13 +180,13 @@ public class JsonReader extends Reader { * @return 有效字符 */ protected char nextGoodChar(boolean allowComment) { - char[] text0 = this.text; - int end = this.limit; - int curr = ++this.position; - char c = text0[curr]; + char c = this.text[++this.position]; if (c > ' ' && c != '/') { return c; } + char[] text0 = this.text; + int end = this.limit; + int curr = this.position; for (; curr <= end; curr++) { c = text0[curr]; if (c > ' ') { @@ -419,52 +419,28 @@ public class JsonReader extends Reader { if (negative) { throw new ConvertException("illegal escape(" + firstchar + ") (position = " + position + ")"); } - char c = nextChar(); - if (c != 'a') { - throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")"); - } - c = nextChar(); - if (c != 'N') { - throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")"); + if (nextChar() != 'a' || nextChar() != 'N') { + throw new ConvertException("illegal escape(" + text[position] + ") (position = " + position + ")"); } if (quote) { - c = nextChar(); + char c = nextChar(); if (c != '"' && c != '\'') { throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")"); } } return 0; // NaN 返回0; } else if (firstchar == 'I') { // Infinity - char c = nextChar(); - if (c != 'n') { - throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")"); - } - c = nextChar(); - if (c != 'f') { - throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")"); - } - c = nextChar(); - if (c != 'i') { - throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")"); - } - c = nextChar(); - if (c != 'n') { - throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")"); - } - c = nextChar(); - if (c != 'i') { - throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")"); - } - c = nextChar(); - if (c != 't') { - throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")"); - } - c = nextChar(); - if (c != 'y') { - throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")"); + if (nextChar() != 'n' + || nextChar() != 'f' + || nextChar() != 'i' + || nextChar() != 'n' + || nextChar() != 'i' + || nextChar() != 't' + || nextChar() != 'y') { + throw new ConvertException("illegal escape(" + text[position] + ") (position = " + position + ")"); } if (quote) { - c = nextChar(); + char c = nextChar(); if (c != '"' && c != '\'') { throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")"); } @@ -582,52 +558,28 @@ public class JsonReader extends Reader { if (negative) { throw new ConvertException("illegal escape(" + firstchar + ") (position = " + position + ")"); } - char c = nextChar(); - if (c != 'a') { - throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")"); - } - c = nextChar(); - if (c != 'N') { - throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")"); + if (nextChar() != 'a' || nextChar() != 'N') { + throw new ConvertException("illegal escape(" + text[position] + ") (position = " + position + ")"); } if (quote) { - c = nextChar(); + char c = nextChar(); if (c != '"' && c != '\'') { throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")"); } } return 0L; // NaN 返回0; } else if (firstchar == 'I') { // Infinity - char c = nextChar(); - if (c != 'n') { - throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")"); - } - c = nextChar(); - if (c != 'f') { - throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")"); - } - c = nextChar(); - if (c != 'i') { - throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")"); - } - c = nextChar(); - if (c != 'n') { - throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")"); - } - c = nextChar(); - if (c != 'i') { - throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")"); - } - c = nextChar(); - if (c != 't') { - throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")"); - } - c = nextChar(); - if (c != 'y') { - throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")"); + if (nextChar() != 'n' + || nextChar() != 'f' + || nextChar() != 'i' + || nextChar() != 'n' + || nextChar() != 'i' + || nextChar() != 't' + || nextChar() != 'y') { + throw new ConvertException("illegal escape(" + text[position] + ") (position = " + position + ")"); } if (quote) { - c = nextChar(); + char c = nextChar(); if (c != '"' && c != '\'') { throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")"); }