FastJson 使用
来源:互联网 发布:0基础大数据培训多少钱 编辑:程序博客网 时间:2024/05/19 17:25
FastJson 使用
类库路径
compile 'com.alibaba:fastjson:1.+'
JsonObject
{ "four": "four", "one": "one", "trhee": "trhee", "two": "two"}
使用集合解析
Map<String,String> data=JSON.parseObject(str,new TypeReference<Map<String,String>>(){}.getType());
使用 key-value 的BEAN解析
public class JsonBean { private String four; private String one; private String trhee; private String two;}JsonBean data = JSON.parseObject(str,JsonBean.class);
JsonArray
[ { "four": "four", "one": "one", "trhee": "trhee", "two": "two" } ]
使用集合解析
List<Map<String,String>> data=JSON.parseObject(str,new TypeReference<List<Map<String,String>>>(){}.getType());
使用 key-value 的BEAN解析
public class JsonBean { private String four; private String one; private String trhee; private String two;}List<JsonBean> data=JSON.parseObject(str,new TypeReference<List<JsonBean>>(){}.getType());
复杂的json
[ { "one": [ { "one1": "one1" }, { "one2": "one2" }, { "one3": "one3" }, { "one4": "one4" } ], "two": [ { "two1": "two1" }, { "two2": "two2" }, { "two3": "two3" } ] }]
使用集合解析
List<Map<String,List<Map<String,String>>>> data = JSON.parseObject(str,new TypeReference<List<Map<String,List<Map<String,String>>>>>(){}.getType());
使用 list 的Bean 解析
public class JsonBean { private List<OneBean> one; private List<TwoBean> two; public List<OneBean> getOne() { return one; } public void setOne(List<OneBean> one) { this.one = one; } public List<TwoBean> getTwo() { return two; } public void setTwo(List<TwoBean> two) { this.two = two; } public static class OneBean { /** * one1 : one1 * one2 : one2 * one3 : one3 * one4 : one4 */ private String one1; private String one2; private String one3; private String one4; public String getOne1() { return one1; } public void setOne1(String one1) { this.one1 = one1; } public String getOne2() { return one2; } public void setOne2(String one2) { this.one2 = one2; } public String getOne3() { return one3; } public void setOne3(String one3) { this.one3 = one3; } public String getOne4() { return one4; } public void setOne4(String one4) { this.one4 = one4; } } public static class TwoBean { /** * two1 : two1 * two2 : two2 * two3 : two3 */ private String two1; private String two2; private String two3; public String getTwo1() { return two1; } public void setTwo1(String two1) { this.two1 = two1; } public String getTwo2() { return two2; } public void setTwo2(String two2) { this.two2 = two2; } public String getTwo3() { return two3; } public void setTwo3(String two3) { this.two3 = two3; } }}JsonBean data = JSON.parseObject(str,JsonBean.class);
将对象转换为字符串
MapListList<Map<..>>List<Bean>String jsonString = JSON.toJSONString(Map | List | List<Map<..>> | List<Bean>);
0 0
- 使用fastJSON
- FastJson使用
- FastJSON使用
- fastJson使用
- fastjson 使用
- fastjson 使用
- FastJson使用
- fastjson使用
- fastJSON使用
- FastJson 使用
- FastJson使用
- FastJson使用
- fastjson使用
- FastJson使用
- Fastjson使用
- FastJson 使用
- fastjson使用
- fastjson使用
- 2016年农民工监测调查报告(zz)
- 递归(循环)神经网络(RNN)简介
- Systick滴答定时器-延时函数
- 摄影测量空间后方交会外方位元素的解算程序
- 1031: 求车速
- FastJson 使用
- mysql高可用方案对比
- Android 基础
- 泛型
- C++编码规则------注释
- HDU 2256 Problem of Precision(矩阵快速幂)
- UNIX文件目录管理基本命令之who登录当前系统用户信息
- HashMap多线程死循环问题
- 常用Java设计模式系列(3)- 代理模式