fastjson解析任意json
fastjson解析任意json到bean
package com.base.config; import java.util.List; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; public class JsonParse { public static void main(String[] args) { String arrJson = "[{\"id\":1,\"mobile\":15809619172},{\"id\":2,\"mobile\":14588827746}]";
List<Student> stus = JSONArray.parseArray(arrJson, Student.class); System.out.println("array json的解析结果:"); for (Student stu : stus) {
System.out.println(stu);
} String beanJson = "{\"id\":1,\"mobile\":15809619172}";
Student stu = JSONObject.parseObject(beanJson, Student.class);
System.out.println("beanjson的解析结果:");
System.out.println(stu); } }
package com.base.config;
public class Student {
private int id;
private String mobile;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
@Override
public String toString() {
return "Student [id=" + id + ", mobile=" + mobile + "]";
}
}
array json的解析结果:
Student [id=1, mobile=15809619172]
Student [id=2, mobile=14588827746]
beanjson的解析结果:
Student [id=1, mobile=15809619172]
这样解析效率很高,而且代码非常简单。比json-lib库要简化非常多。所以强烈推荐使用fastjson.
fastjson解析任意json的更多相关文章
- JSON 之FastJson解析
http://blog.sina.com.cn/s/blog_7ffb8dd501013qas.html 一.阿里巴巴FastJson是一个Json处理工具包,包括“序列化”和“反序列化”两部分,它具 ...
- (转)JSON 之FastJson解析
一.阿里巴巴FastJson是一个Json处理工具包,包括“序列化”和“反序列化”两部分,它具备如下特征:速度最快,测试表明,fastjson具有极快的性能,超越任其他的Java Json parse ...
- Json,Gson,FastJson解析笔记
Json,Gson,FastJson解析笔记 1.将JavaBean转换成Json对象: public static String CreatJsonFromObject(Object key,Obj ...
- fastJson解析复杂的json字符串,经测试已经成功解析
要解析的json数据格式为: HTTP/1.1 200 OK Content-Type: text/jsv Content-Length: length { ResponseStatus: { }, ...
- Spring Boot返回json数据及完美使用FastJson解析Json数据
Spring Boot返回json数据 视频地址:http://www.iqiyi.com/w_19rubxzsr5.html 博文参考:https://blog.csdn.net/linxingl ...
- fastjson解析json数组
1.fastjson解析json数组(直接上代码) import java.util.ArrayList; import java.util.List; import com.alibaba.fast ...
- JavaWeb_(Jar)使用fastjson解析json和序列化对象
菜鸟教程 传送门 JSON官网 传送门 fastjson插件下载 传送门 序列化[百度百科]:序列化 (Serialization)是将对象的状态信息转换为可以存储或传输的形式的过程.在序列化期间,对 ...
- FastJson解析Json,封装JavaBean对象
获取到前端的Json,后台对应封装JavaBean对象,对其解析赋值 获取到前端的json,对其进行分析 1.获取最外层前端json对应得JavaBean (1)未分析格式的json串 (2)初步格式 ...
- Scala中使用fastJson 解析json字符串
Scala中使用fastJson 解析json字符串 添加依赖 2.解析json字符 2.1可以通过JSON中的parseObject方法,把json字符转转换为一个JSONObject对象 2.2然 ...
随机推荐
- Could not create the view: An unexpected exception was thrown. 电脑突然断电,myeclipse非正常关闭,出现错误
电脑突然断电,myeclipse非正常关闭,“Package Explorer”非正常显示,出现错误“Could not create the view: An unexpected exceptio ...
- HDU1568斐波那契推理
Fibonacci Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- Linux设置IP
进入 vi /etc/sysconfig/network-scripts/ifcfg-eth0 root # ifconfig eth0 192.168.22.232 root # route ad ...
- linux 小喇叭 没了
Waiting for sound system to respond 方法: # pulseaudio --start -D W: main.c: This program is not inten ...
- jQuery Mobile 基础(第二章)
1.可折叠块: <div data-role="collapsible"> <h1>点击我 - 我可以折叠!</h1> <p>我是可 ...
- Xamarin.Android开发实践(十五)
Xamarin.Android学习之应用程序首选项 一.前言 任何App都会存在设置界面,如果开发者利用普通控件并绑定监听事件保存设置,这 一过程会非常的枯燥,而且耗时.我们可以看到Android系统 ...
- SQLServer中临时表与表变量的区别分析(转)
在实际使用的时候,我们如何灵活的在存储过程中运用它们,虽然它们实现的功能基本上是一样的,可如何在一个存储过程中有时候去使用临时表而不使用表变量,有时候去使用表变量而不使用临时表呢? 临时表 临时表与永 ...
- lr_save_var字符串截取总结
函数作用: 将一个变化长度的字符串保存到parameter中. 用法实例: 此处讲解函数: Action() { web_save_timestamp_param("tStamp&q ...
- Swift 1.1语言函数参数的特殊情况本地参数名外部参数名
Swift 1.1语言函数参数的特殊情况本地参数名外部参数名 7.4 函数参数的特殊情况 声明定义有参函数时,为函数的每一个参数都定义了参数名称.根据参数名定义的形式不同,函数参数包括本地参数和外部 ...
- 贪心 BestCoder Round #39 1001 Delete
题目传送门 /* 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 否则再在tot里减去多余的即为答案 用set容器也可以做,思路一样 */ # ...