Java中Json转换Bean对象并忽略大小写!

import com.sdzn.vo.ICPostJsonBeanVO;

public class test {

public static void main(String[] args) {

String tString = “{\”FuncName\”:\”UploadGroupInfo\”,\”ParamNum\”:\”1\”,\”ParamValue\”:\”444\”}”;

JSONObject jsonObj1 = JSONObject.fromObject(tString);

JsonConfig config = new JsonConfig();

config.setJavaIdentifierTransformer(new JavaIdentifierTransformer() {

@Override
public String transformToJavaIdentifier(String str) {

char[] chars = str.toCharArray();

chars[0] = Character.toLowerCase(chars[0]);

return new String(chars);

}

});

config.setRootClass(ICPostJsonBeanVO.class);

ICPostJsonBeanVO p2 = (ICPostJsonBeanVO) JSONObject.toBean(jsonObj1,
config);

System.out.println(“json转化为对象:方法名:” + p2.getFuncName() + “;数量:”
+ p2.getParamNum() + “值:” + p2.getParamValue());

}

}

发表评论