public class JSONTokener extends ReaderWrapper
Modifier and Type | Field and Description |
---|---|
static int |
EOF
定义结束(End of stream)为:0
|
raw
Constructor and Description |
---|
JSONTokener(CharSequence s,
boolean ignoreZeroWithChar)
从字符串中构建
|
JSONTokener(InputStream inputStream,
boolean ignoreZeroWithChar)
从InputStream中构建,使用UTF-8编码
|
JSONTokener(Reader reader,
boolean ignoreZeroWithChar)
从Reader中构建
|
Modifier and Type | Method and Description |
---|---|
void |
back()
将标记回退到第一个字符,重新开始解析新的JSON
|
void |
checkEnd()
检查是否到了结尾
如果读取完毕后还有未读的字符,报错 |
boolean |
end() |
protected char |
getPrevious()
获取上一个读取的字符,如果没有读取过则返回'\0'
|
boolean |
more()
源字符串是否有更多的字符
|
char |
next()
获得源字符串中的下一个字符
|
char[] |
next(int n)
获得接下来的n个字符
|
char |
nextClean()
获得下一个字符,跳过空白符
|
char |
nextColon()
获取下一个冒号,非冒号则抛出异常
|
String |
nextKey(char c)
读取下一个JSON中的key,支持不带引号的key
|
String |
nextString()
读取一个字符串,包括:
使用引号包裹的字符串,自动反转义。
|
char |
nextTokenChar()
获取下一个token字符
|
char |
nextUnicode()
获取16进制unicode转义符对应的字符值,如:
'4f60' -> '你' |
String |
nextUnwrapString(char c)
获得下一个字符串,此字符串不以引号包围,不会处理转义符,主要解析:
非严格的key(无引号包围的key)
boolean值的字符串表示
Number值的字符串表示
null的字符串表示
|
String |
nextWrapString(char quote)
返回当前位置到指定引号前的所有字符,反斜杠的转义符也会被处理。
|
JSONException |
syntaxError(String message)
Make a JSONException to signal a syntax error.
|
String |
toString()
Make a printable string of this JSONTokener.
|
public static final int EOF
public JSONTokener(InputStream inputStream, boolean ignoreZeroWithChar) throws JSONException
inputStream
- InputStreamignoreZeroWithChar
- 是否忽略零宽字符JSONException
- JSON异常,包装IO异常public JSONTokener(CharSequence s, boolean ignoreZeroWithChar)
s
- JSON字符串ignoreZeroWithChar
- 是否忽略零宽字符public JSONTokener(Reader reader, boolean ignoreZeroWithChar)
reader
- ReaderignoreZeroWithChar
- 是否忽略零宽字符public void back() throws JSONException
JSONException
- JSON异常,包装IO异常public boolean end()
public void checkEnd()
public boolean more() throws JSONException
JSONException
- JSON异常,包装IO异常public char next() throws JSONException
JSONException
- JSON异常,包装IO异常protected char getPrevious()
public char nextUnicode()
'4f60' -> '你'
public char[] next(int n) throws JSONException
n
- 字符数JSONException
- 如果源中余下的字符数不足以提供所需的字符数,抛出此异常public char nextTokenChar() throws JSONException
JSONException
- 非Token字符public char nextClean() throws JSONException
JSONException
- 获得下一个字符时抛出的异常public String nextKey(char c) throws JSONException
c
- 当前字符JSONException
- 非引号包裹的字符串public char nextColon() throws JSONException
JSONException
- 非冒号字符public String nextString() throws JSONException
JSONException
- 出现无结束的字符串时抛出此异常public String nextUnwrapString(char c) throws JSONException
c
- 首个字符JSONException
- 读取空串时抛出此异常public String nextWrapString(char quote) throws JSONException
quote
- 字符引号, 包括 "
(双引号) 或 '
(单引号)。JSONException
- 出现无结束的字符串时抛出此异常public JSONException syntaxError(String message)
message
- 错误消息Copyright © 2025. All rights reserved.