分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow
也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!
在做数据转换为JSON格式时:
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()); }}
出现了如下错误:
thread "main" net.sf.json.JSONException: java.lang.NoSuchMethodException: Property 'age' has no getter method in class 'class T'
原因是 声明bean为public class 必须是public