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然 ...
随机推荐
- Linux 底下使用C 对文件进行遍历
#include <stdio.h>#include <stdlib.h>main (int argc,char *argv[]){char ch;FILE *fp;int i ...
- 【读书笔记】读《JavaScript设计模式》之工厂模式
一个类或对象中往往会包含别的对象.在创建这种成员对象时,你可能习惯于使用常规方式,也即用new关键字和类构造函数.问题在于这回导致相关的两个类之间产生依赖性. 工厂模式用于消除这两个类之间的依赖性,它 ...
- 在《The DevOps 2.0 Toolkit》测试时要作的ansible的配置更改
这本极有用.要看完,测试完. 原生的配置: - name: Docker Compose is present get_url: url: https://github.com/docker/comp ...
- 实现Activity刷新(转)
目前刷新Acitivity,只想到几种方法.仅供参考,如果您有更好的方法,请赐教. 程序界面: 点击refresh view可以刷新界面,点击write content可以在EditText中自动写入 ...
- 铭飞MCMS内容管理系统完整开源版J2EE代码
当前版本:4.6.0铭飞MS官网:http://ms.mingsoft.net官网同时提供一键运行版本下载,请步移官网....QQ交流群号1:221335098很多人说铭飞MCMS是大天朝国唯一完整开 ...
- 无法获得锁 /var/lib/dpkg/lock - open (11: 资源临时不可用)
转自:http://www.cnblogs.com/ManMonth/archive/2010/01/14/1648010.html 问题: 运行程序更新时出现报错: 无法获得锁 /var/lib/d ...
- 浅谈C/C++中的顺序点和副作用
一.副作用(side effect) 表达式有两种功能:每个表达式都产生一个值( value ),同时可能包含副作用( side effect ).副作用是指改变了某些变量的值. 如: 1:20 ...
- 其他主流开源硬件简介BeagleBone Black快速入门
其他主流开源硬件简介BeagleBone Black快速入门 1.3 其他主流开源硬件简介 开源硬件种类繁多,但主要有两款开源硬件常与BeagleBone比较.它们就是Arduino和Raspberr ...
- http://www.cnblogs.com/Matrix54/archive/2012/05/03/2481260.html
http://www.cnblogs.com/Matrix54/archive/2012/05/03/2481260.html
- 游戏 slider
using UnityEngine; using System.Collections; public class La : MonoBehaviour { float verticalValue=0 ...