枚举对象如下:
public enum ExamType {
CHINESE("语文", "01"),
MATH("数学", "02"),
MATH_ARTS("数学文", "03"),
MATH_SCIENCE("数学理", "04"),
ENGLISH("英语", "05"),
POLITICS("政治", "06"),
HISTORY("历史", "07"),
GEOGRAPHY("地理", "08"),
PHYSICS("物理", "09"),
CHEMISTRY("化学", "10"),
BIOLOGY("生物", "11");
public String name;
public String code;
private ExamType(String name, String code) {
this.name = name;
this.code = code;
}
@Override
public String toString() {
return String.format("{\"name\":\"%s\",\"code\":\"%s\"}", name, code);
}
}
ajax请求一个ExamType 的list返回值如下:
["CHINESE", "MATH_SCIENCE", "ENGLISH", "PHYSICS", "CHEMISTRY", "BIOLOGY"]
但是想要的结果是这样的:
[
{
"name": "语文",
"code": "01"
},
{
"name": "数学理",
"code": "04"
},
{
"name": "英语",
"code": "05"
},
{
"name": "物理",
"code": "09"
},
{
"name": "化学",
"code": "10"
},
{
"name": "地理",
"code": "08"
}
]
请问要怎么实现?