/** * 取枚举的json字符串 * * @return */ public static String getJsonStr() { PayTypeEnum[] enums = PayTypeEnum.values(); StringBuffer jsonStr = new StringBuffer("["); for (PayTypeEnum senum : enums) { if (!"[".equals(jsonStr.toString())) { jsonStr.append(","); } jsonStr.append("{id:'").append(senum).append("',desc:'").append(senum.getDesc()).append("'}"); } jsonStr.append("]"); return jsonStr.toString(); }
public static PayTypeEnum getEnum(String name) { PayTypeEnum[] arry = PayTypeEnum.values(); for (int i = 0; i < arry.length; i++) { if (arry[i].name().equalsIgnoreCase(name)) { return arry[i]; } } return null; }
public static Map<String, Map<String, Object>> toMap() { PayTypeEnum[] ary = PayTypeEnum.values(); Map<String, Map<String, Object>> enumMap = new HashMap<String, Map<String, Object>>(); for (int num = 0; num < ary.length; num++) { Map<String, Object> map = new HashMap<String, Object>(); String key = ary[num].name(); map.put("desc", ary[num].getDesc()); enumMap.put(key, map); } return enumMap; }
@SuppressWarnings({"rawtypes", "unchecked"}) public static List toList() { PayTypeEnum[] ary = PayTypeEnum.values(); List list = new ArrayList(); for (int i = 0; i < ary.length; i++) { Map<String, String> map = new HashMap<String, String>(); map.put("desc", ary[i].getDesc()); map.put("name", ary[i].name()); list.add(map); } return list; }