We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
public static Integer castToInt(Object value){ if(value == null){ return null; }
if(value instanceof Integer){ return (Integer) value; } if(value instanceof BigDecimal){ return intValue((BigDecimal) value); } if(value instanceof Number){ return ((Number) value).intValue(); } if(value instanceof String){ String strVal = (String) value; if(strVal.length() == 0 // || "null".equals(strVal) // || "NULL".equals(strVal)){ return null; } if(strVal.indexOf(',') != -1){ strVal = strVal.replaceAll(",", ""); // 此处删除了逗号 } Matcher matcher = NUMBER_WITH_TRAILING_ZEROS_PATTERN.matcher(strVal); if(matcher.find()) { strVal = matcher.replaceAll(""); } return Integer.parseInt(strVal); } if(value instanceof Boolean){ return (Boolean) value ? 1 : 0; } if(value instanceof Map){ Map map = (Map) value; if(map.size() == 2 && map.containsKey("andIncrement") && map.containsKey("andDecrement")){ Iterator iter = map.values().iterator(); iter.next(); Object value2 = iter.next(); return castToInt(value2); } } throw new JSONException("can not cast to int, value : " + value); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
public static Integer castToInt(Object value){
if(value == null){
return null;
}
The text was updated successfully, but these errors were encountered: