JSON Property 'xxx' has no getter method in class 'class xx

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

在做数据转换为JSON格式时:

import net.sf.json.JSONArray;class Tprivate 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            

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow

这里写图片描述

猜你喜欢

转载自blog.csdn.net/hffygc/article/details/83889475
今日推荐