JSONObject中的一個(gè)小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檩帐,并出現(xiàn)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
這兩個(gè)之間的差別僅僅在于Accreditation中的屬性一個(gè)是aAdvice,一個(gè)是aadvice。
所以建議toBean中的bean中的屬性名的第二個(gè)字母不要大寫