正在回答 回答被采纳积分+1
package com.imooc.json;
import java.util.Calendar;
import com.alibaba.fastjson.JSON;
public class FastJsonSample1 {
public static void main(String[] args) {
Employee employee = new Employee();
employee.setEmpno(4488);
employee.setEname("王晓东");
employee.setJob("客户经理");
employee.setSalary(10000f);
employee.setDname("市场部");
Calendar c = Calendar.getInstance();
c.set(2019, 0, 30, 0, 0, 0);
employee.setHdate(c.getTime());
String json = JSON.toJSONString(employee);
System.out.println(json);
Employee emp = JSON.parseObject(json, Employee.class);
System.out.println(emp.getEname());
}
}
package com.imooc.json;
import java.util.Date;
import com.alibaba.fastjson.annotation.JSONField;
public class Employee {
private Integer empno;
private String ename;
private String job;
// @JSONField(format="yyyy-MM-dd HH:mm:ss SSS")
@JSONField(name = "hiredata", format="yyyy-MM-dd")
private Date hdate;
private Float salary;
@JSONField(serialize = false)
private String dname;
public Integer getEmpno() {
return empno;
}
public void setEmpno(Integer empno) {
this.empno = empno;
}
public String getEname() {
return ename;
}
public void setEname(String aname) {
this.ename = aname;
}
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
public Date getHdate() {
return hdate;
}
public void setHdate(Date hdate) {
this.hdate = hdate;
}
public Float getSalary() {
return salary;
}
public void setSalary(Float salary) {
this.salary = salary;
}
public String getDname() {
return dname;
}
public void setDname(String dname) {
this.dname = dname;
}
}
- 参与学习 人
- 提交作业 676 份
- 解答问题 9666 个
本阶段将从前端网页搭建入手,到Java Web基础,前后端结合助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星