FastJson_exc1
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了FastJson_exc1相关的知识,希望对你有一定的参考价值。
1 package cn.kjxy.FASTJSON; 2 3 import java.util.List; 4 5 import com.alibaba.fastjson.JSON; 6 7 /** 8 * FastJson解析json数据 9 * 注意:1.需要导入fastjson-1.1.22.jar包 10 * 2.自定义的属性与对象名一致才能被解析 11 * 3.每个类需要getSet方法,Gson解析可以不要 12 * 13 * @author Administrator 14 * 15 */ 16 class DevelopmentDep { 17 private int no; 18 private String name; 19 private List<Deper> list; 20 21 public int getNo() { 22 return no; 23 } 24 25 public void setNo(int no) { 26 this.no = no; 27 } 28 29 public String getName() { 30 return name; 31 } 32 33 public void setName(String name) { 34 this.name = name; 35 } 36 37 public List<Deper> getList() { 38 return list; 39 } 40 41 public void setList(List<Deper> list) { 42 this.list = list; 43 } 44 45 @Override 46 public String toString() { 47 return "DevelopmentDep [no=" + no + ", name=" + name + ", list=" + list 48 + "]"; 49 } 50 51 } 52 53 class Deper { 54 private String name; 55 private double salary; 56 57 @Override 58 public String toString() { 59 return "Deper [name=" + name + ", salary=" + salary + "]"; 60 } 61 62 public String getName() { 63 return name; 64 } 65 66 public void setName(String name) { 67 this.name = name; 68 } 69 70 public double getSalary() { 71 return salary; 72 } 73 74 public void setSalary(double salary) { 75 this.salary = salary; 76 } 77 78 } 79 80 public class Demo1 { 81 public static void main(String[] args) { 82 String json = "[{no:1001,name:‘研发部‘,list:[{name:‘李晨‘,salary:30000},{name:‘王思远‘,salary:3}]},{no:2,name:‘市场部‘,list:[{name:‘周周‘,salary:19000}]}]"; 83 parserJsonFromFastJson(json); 84 } 85 86 private static void parserJsonFromFastJson(String json) { 87 // TODO Auto-generated method stub 88 List<DevelopmentDep> list = JSON.parseArray(json, DevelopmentDep.class); 89 System.out.println(list); 90 } 91 }
以上是关于FastJson_exc1的主要内容,如果未能解决你的问题,请参考以下文章