
com.ajaxjs.js.jsonparser.JSONParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ajaxjs-base Show documentation
Show all versions of ajaxjs-base Show documentation
A pure Java library that provides many tools, utils, and functions.
/**
* Copyright Sp42 [email protected]
*
* 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.ajaxjs.js.jsonparser;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import com.ajaxjs.keyvalue.MappingValue;
import com.ajaxjs.util.CommonUtil;
/**
* 主要的方法入口 parse()。 还有其他的一些工具方法
*
* @author Frank Cheung
*
*/
public class JSONParser {
/**
* 是否空格字符
*
* @param c 传入的字符
* @return 是否空格字符
*/
public static boolean isSpace(char c) {
return c == ' ' || c == '\t' || c == '\n';
}
/**
* 是否字符或者下划线
*
* @param c 传入的字符
* @return 是否字符或者下划线
*/
public static boolean isLetterUnderline(char c) {
return (c >= 'a' && c <= 'z') || c == '_';
}
/**
* 是否数字字符
*
* @param c 传入的字符
* @return 是否数字字符
*/
public static boolean isNum(char c) {
return c >= '0' && c <= '9';
}
/**
* 是否数字字符或小数
*
* @param c 传入的字符
* @return 是否数字字符或小数
*/
public static boolean isDecimal(char c) {
return isNum(c) || c == '.';
}
/**
* 是否字符或者数字或下划线
*
* @param c 传入的字符
* @return 是否字符或者数字或下划线
*/
public static boolean isNumLetterUnderline(char c) {
return isLetterUnderline(c) || isNum(c) || c == '_';
}
/**
* 是否引号字符串,JSON 支持 " 和 ' 两种的字符串字面量
*
* @param c 传入的字符
* @return 是否引号字符串
*/
public static boolean hasQuoataion(char c) {
return c != '\"' && c != '\'';
}
/**
* 这是一个更加的 json 解析方法 就算是{'a:a{dsa}':"{fdasf[dd]}"} 这样的也可以处理
* 当然{a:{b:{c:{d:{e:[1,2,3,4,5,6]}}}}}更可以处理
*
* @param jsonStr 合法格式的 json 字符串
* @return 有可能 map 有可能是 list
*/
public static Object json2Map2(String jsonStr) {
if (CommonUtil.isEmptyString(jsonStr))
return null;
Stack
© 2015 - 2025 Weber Informatics LLC | Privacy Policy