Net.Sf.Json java Object to JsonObject

 

public class People{

  private String name;

  public void setName(String name){

    this.name = name;

  }

  public String name{

  return name;

  }

  public void setAge(int age){

  this.age = age;

  }

  public int age{

  return age;

  }

}

import net.sf.Json..

public class test{

  public static void main(String args[]){

  People aPeople = new People();

  aPeople.name = "name";

  aPeople.age = 20

  JsonObject jsonObj = JsonObject.fromObject(aPeople);

  String jsonStr = jsonObj.toString();

  }

}

注意点 、 People类的set get 方法要写 

 

posted on 2016-03-18 14:39  码农时刻  阅读(215)  评论(0编辑  收藏  举报