- public static String toJson(Enum<?>[] enumValues) throws IllegalAccessException, InvocationTargetException {
- StringBuffer buffer=new StringBuffer("[");
- boolean obj1st=true;
- for (Object obj : enumValues) {
- if(obj1st){
- obj1st=false;
- }else{
- buffer.append(",");
- }
- buffer.append("{");
-
- Method[] methods = obj.getClass().getMethods();
- boolean method1st=true;
- for (int i = 0; i < methods.length; i++) {
-
- Method method = methods[i];
-
- if (method.getName().startsWith("get") && method.getParameterTypes().length == 0 && !method.getName().contains("Class")) {
-
- if(method1st){
- method1st=false;
- }else{
- buffer.append(",");
- }
-
- String name = method.getName().replace("get","");
- buffer.append("\"" + name.substring(0, 1).toLowerCase() + name.substring(1) + "\":\"");
- buffer.append(method.invoke(obj)+"\"");
- }
- }
- buffer.append("}");
- }
- buffer.append("]");
- return buffer.toString();
- }
posted @
2018-05-19 09:48
sundaysios
阅读(
104)
评论()
收藏
举报