Chinaunix首页 | 论坛 | 博客
  • 博客访问: 302312
  • 博文数量: 93
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 830
  • 用 户 组: 普通用户
  • 注册时间: 2016-02-25 10:44
个人简介

一杯茶,一台电脑

文章分类

全部博文(93)

文章存档

2018年(4)

2017年(57)

2016年(32)

分类: Java

2016-12-30 15:50:58


点击(此处)折叠或打开

  1. //testdemo.java

  2. package testdemo;

  3. import java.util.ArrayList;
  4. import java.util.List;

  5. import com.alibaba.fastjson.JSON;

  6. public class demo {

  7.     public static void main(String[] args) {
  8.         
  9.         List<person> plist = new ArrayList<>();
  10.         
  11.         person p = new person("admin","admin123","yinChuan",24,"Man","353515","3535");
  12.         person p_1 = new person("guest","guest345","HuBei",24,"Man","1269694461","xbsd123");
  13.         plist.add(p);
  14.         plist.add(p_1);
  15.         
  16.         String json_str = JSON.toJSONString(plist);
  17.         System.out.println(json_str);
  18.         
  19. //        person p1= JSON.parseObject(json_str,person.class);
  20. //        System.out.println(p1.getUsername());
  21. //        System.out.println(p1.getUserpwd());
  22.         
  23.     }
  24.     
  25.     

  26. }

  27. //person.java

  28. package testdemo;

  29. import java.io.Serializable;

  30. public class person implements Serializable{
  31.     private static final long serialVersionUID = 1L;
  32.     
  33.     private String username;
  34.     private String userpwd;
  35.     private String addr;
  36.     private int age;
  37.     private String sex;
  38.     private String wechat;
  39.     private String qq;
  40.     public String getUsername() {
  41.         return username;
  42.     }
  43.     public void setUsername(String username) {
  44.         this.username = username;
  45.     }
  46.     public String getUserpwd() {
  47.         return userpwd;
  48.     }
  49.     public void setUserpwd(String userpwd) {
  50.         this.userpwd = userpwd;
  51.     }
  52.     public String getAddr() {
  53.         return addr;
  54.     }
  55.     public void setAddr(String addr) {
  56.         this.addr = addr;
  57.     }
  58.     public int getAge() {
  59.         return age;
  60.     }
  61.     public void setAge(int age) {
  62.         this.age = age;
  63.     }
  64.     public String getSex() {
  65.         return sex;
  66.     }
  67.     public void setSex(String sex) {
  68.         this.sex = sex;
  69.     }
  70.     public String getWechat() {
  71.         return wechat;
  72.     }
  73.     public void setWechat(String wechat) {
  74.         this.wechat = wechat;
  75.     }
  76.     public String getQq() {
  77.         return qq;
  78.     }
  79.     public void setQq(String qq) {
  80.         this.qq = qq;
  81.     }
  82.     public person(String username, String userpwd, String addr, int age, String sex, String wechat, String qq) {
  83.         super();
  84.         this.username = username;
  85.         this.userpwd = userpwd;
  86.         this.addr = addr;
  87.         this.age = age;
  88.         this.sex = sex;
  89.         this.wechat = wechat;
  90.         this.qq = qq;
  91.     }
  92.     public person() {
  93.     }
  94. }

  95. /*
  96. ------------- 结果-------------
  97. [{"addr":"yinChuan","age":24,"qq":"x535","sex":"Man","username":"admin","userpwd":"admin123","wechat":"353532415"},{"addr":"HuBei","age":24,"qq":"xbsd123","sex":"Man","username":"guest","userpwd":"guest345","wechat":"1269694461"}]

  98. */

阅读(710) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~