JSON: Property 'xxx' has no getter method in class 'class xxx' java
在作數據轉換爲JSON格式時:json
[java] view plain copythis
- import net.sf.json.JSONArray;
-
- class T{
- private String name;
- private int age;
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public int getAge() {
- return age;
- }
- public void setAge(int age) {
- this.age = age;
- }
- }
- public class JSONTest2 {
- public static void main(String[] args) {
- T t = new T();
- t.setName("zhangsan");
- t.setAge(20);
-
- JSONArray json = JSONArray.fromObject(t);
- System.out.println(json);
-
- //System.out.println(t.getName());
- //System.out.println(t.getAge());
- }
- }
出現了以下錯誤:spa
- thread "main" net.sf.json.JSONException: java.lang.NoSuchMethodException: Property 'age' has no getter method in class 'class T'
緣由是 聲明bean爲public class 必須是public .net