com.github.quartzwebui.utils.json.JSONParser Maven / Gradle / Ivy
The newest version!
/*
* Copyright 1999-2017 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.quartzwebui.utils.json;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class JSONParser {
private String text;
private int index = 0;
private char ch;
private Token token;
private String stringValue;
private long longValue;
private double doubleValue;
public JSONParser(String text){
this.text = text;
ch = text.charAt(0);
nextToken();
}
public Object parse() {
if (token == Token.LBRACE) {
return parseMap();
}
if (token == Token.INT) {
Object value;
if (this.longValue >= Integer.MIN_VALUE && this.longValue <= Integer.MAX_VALUE) {
value = (int) this.longValue;
} else {
value = this.longValue;
}
nextToken();
return value;
}
if (token == Token.DOUBLE) {
Object value = this.doubleValue;
nextToken();
return value;
}
if (token == Token.STRING) {
Object value = this.stringValue;
nextToken();
return value;
}
if (token == Token.LBRACKET) {
return parseArray();
}
if (token == Token.TRUE) {
nextToken();
return true;
}
if (token == Token.FALSE) {
nextToken();
return false;
}
if (token == Token.NULL) {
nextToken();
return null;
}
throw new IllegalArgumentException("illegal token : " + token);
}
public List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy