Serializable, Comparable<ZSONType>public enum ZSONType extends Enum<ZSONType>
You can use this enum to determine which method in ZSONReader is used to read data. An example is provided as
follows:
String text = "{\"array\": [1, 2.33, true, \"abc\", null]}";
try (ZSONReader reader = new ZSONReader(new StringReader(text))) {
reader.startObject();
if (reader.peek() == ZSONType.NAME) {
reader.readName();
}
if (reader.peek() == ZSONType.ARRAY) {
reader.startArray();
while (reader.hasNext()) {
switch (reader.peek()) {
case INTEGER: {
reader.readInt(); // or reader.readLong()
break;
}
case FLOAT: {
reader.readFloat(); // or reader.readDouble()
break;
}
case BOOLEAN: {
reader.readBoolean();
break;
}
case STRING: {
reader.readString();
break;
}
case NULL: {
reader.readNull();
break;
}
default: {
throw new ZSONException("error type " + reader.peek());
}
}
}
reader.endArray();
}
}
ZSONReader.peek()| 枚举常量 | 说明 |
|---|---|
ARRAY |
Indicates the array type, for example,
[1,2,3]. |
BOOLEAN |
Indicates the boolean type, either
true or false. |
FLOAT |
Indicates the floating point type, for example,
1.23 or 12e3. |
INTEGER |
Indicates the integer type, for example,
123. |
NAME |
Indicates the field name of an object, for example,
"fieldName". |
NULL |
Indicates the null type, for example,
null. |
OBJECT |
Indicates the object type, for example,
{"fieldName": "fieldValue"}. |
STRING |
Indicates the string type, for example,
"fieldValue". |
UNKNOWN |
Indicates an unknown data type.
|
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static ZSONType |
valueOf(String name) |
返回带有指定名称的该类型的枚举常量。
字符串必须与用于声明该类型的枚举常量的
标识符完全匹配。(不允许有多余
的空格字符。)
|
static ZSONType[] |
values() |
按照声明该枚举类型的常量的顺序, 返回
包含这些常量的数组。该方法可用于迭代
常量, 如下所示:
for (ZSONType c : ZSONType.values()) System.out.println(c); |
public static final ZSONType ARRAY
[1,2,3].public static final ZSONType OBJECT
{"fieldName": "fieldValue"}.public static final ZSONType NAME
"fieldName".ZSONReader.readName()public static final ZSONType BOOLEAN
true or false.ZSONReader.readBoolean()public static final ZSONType INTEGER
123.ZSONReader.readInt(),
ZSONReader.readLong()public static final ZSONType FLOAT
1.23 or 12e3.ZSONReader.readFloat(),
ZSONReader.readDouble()public static final ZSONType NULL
null.ZSONReader.readNull()public static final ZSONType STRING
"fieldValue".ZSONReader.readString()public static final ZSONType UNKNOWN
public static ZSONType[] values()
for (ZSONType c : ZSONType.values()) System.out.println(c);
public static ZSONType valueOf(String name)
name - 要返回的枚举常量的名称。IllegalArgumentException - 如果该枚举类型没有带有指定名称的常量NullPointerException - 如果参数为空值