JSONObject中的一个小bug

JSONObject中的一个小bug

From (http://daizhenghua.good.blog.163.com/blog/static/105287726201122339785/)

package com.whut.luzheng.model;

import java.util.Date;

public class Accreditation {
private String aAdvice;
//省去getter和setter
}
JSONObject acc = new JSONObject();
acc.put("aAdvice","123");
Accreditation accreditation = (Accreditation) JSONObject.toBean(acc, Accreditation.class);
System.out.println(accreditation.getAAdvice());//输出null,并出现WARN net.sf.json.JSONObject:431 - Tried to assign property aSignture:java.lang.String to bean of class com.whut.luzheng.model.Accreditation

package com.whut.luzheng.model;

import java.util.Date;

public class Accreditation {
private String aadvice;
//省去getter和setter
}
JSONObject acc = new JSONObject();
acc.put("aadvice","123");
Accreditation accreditation = (Accreditation) JSONObject.toBean(acc, Accreditation.class);
System.out.println(accreditation.getAadvice());//输出123

这两个之间的差别仅仅在于Accreditation中的属性一个是aAdvice,一个是aadvice。

所以建议toBean中的bean中的属性名的第二个字母不要大写

你可能感兴趣的:(JSONObject中的一个小bug)