FastJSON应用前测试
FastJSON 应用前测试
FastJSON是一个很好的java开源json工具类库,相比其他同类的json类库,它的速度的确是fast,最快!但是文档做得不好,在应用前不得不亲测一些功能。\
实际上其他的json处理工具都和它差不多,api也有几分相似。
1、遵循http://json.org标准,为其官方网站收录的参考实现之一。
2、功能qiang打,支持JDK的各种类型,包括基本的JavaBean、Collection、Map、Date、Enum、泛型。
3、无依赖,不需要例外额外的jar,能够直接跑在JDK上。
4、开源,使用Apache License 2.0协议开源。http://code.alibabatech.com/wiki/display/FastJSON/Home
SVN:http://code.alibabatech.com/svn/fastjson/trunk/
WIKI:http://code.alibabatech.com/wiki/display/FastJSON/Home
Issue Tracking:http://code.alibabatech.com/jira/browse/FASTJSON
public static final Object parse(String text); // 把JSON文本parse为JSONObject或者JSONArray
public static final JSONObject parseObject(String text); // 把JSON文本parse成JSONObject
public static final <T> T parseObject(String text, Class<T> clazz); // 把JSON文本parse为JavaBean
public static final JSONArray parseArray(String text); // 把JSON文本parse成JSONArray
public static final <T> List<T> parseArray(String text, Class<T> clazz); //把JSON文本parse成JavaBean集合
public static final String toJSONString(Object object); // 将JavaBean序列化为JSON文本
public static final String toJSONString(Object object, boolean prettyFormat); // 将JavaBean序列化为带格式的JSON文本
public static final Object toJSON(Object javaObject); 将JavaBean转换为JSONObject或者JSONArray。
3、有关类库的一些说明
package lavasoft.stu.json; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer; import java.util.*; /**
* Created by IntelliJ IDEA.
*
* @author leizhimin 11-11-22 上午9:15
*/
public class Foo {
private String vString = "vStringhehhehe";
private char vchar = 'x'; private byte vbyte = ;
private short vshort = ;
private int vint = ;
private long vlong = 9999999L; private float vfloat = 12.1f;
private double vdouble = 22.203d; private boolean vboolean = false; // private Date vdate = new Date();
private Date dddd = new Date();
private Date vDate = new Date();
private Date v_Date = new Date();
private Object vnull = null; private String[] avString = {"aaa", "bbb", "ccc"};
private int[] avint = {, , , };
private boolean[] avboolean = {true, false, true, true}; private List<String> listString = new ArrayList<String>();
private Map<String, String> map = new HashMap<String, String>(); private Bar bar = new Bar();
private Bar[] avBar = {new Bar(), new Bar()};
private List<Bar> listBar = new ArrayList<Bar>(); {
listString.add("listString1");
listString.add("listString2");
listString.add("listString3"); map.put("x", "s11111x");
map.put("y", "s22222y");
map.put("z", "s33333z"); listBar.add(new Bar());
listBar.add(new Bar());
listBar.add(new Bar());
} public String getvString() {
return vString;
} public void setvString(String vString) {
this.vString = vString;
} public char getVchar() {
return vchar;
} public void setVchar(char vchar) {
this.vchar = vchar;
} public byte getVbyte() {
return vbyte;
} public void setVbyte(byte vbyte) {
this.vbyte = vbyte;
} public short getVshort() {
return vshort;
} public void setVshort(short vshort) {
this.vshort = vshort;
} public int getVint() {
return vint;
} public void setVint(int vint) {
this.vint = vint;
} public long getVlong() {
return vlong;
} public void setVlong(long vlong) {
this.vlong = vlong;
} public float getVfloat() {
return vfloat;
} public void setVfloat(float vfloat) {
this.vfloat = vfloat;
} public double getVdouble() {
return vdouble;
} public void setVdouble(double vdouble) {
this.vdouble = vdouble;
} public boolean isVboolean() {
return vboolean;
} public void setVboolean(boolean vboolean) {
this.vboolean = vboolean;
} public Date getDddd() {
return dddd;
} public void setDddd(Date dddd) {
this.dddd = dddd;
} public Date getV_Date() {
return v_Date;
} public void setV_Date(Date v_Date) {
this.v_Date = v_Date;
} public Date getvDate() {
return vDate;
} public void setvDate(Date vDate) {
this.vDate = vDate;
} public Object getVnull() {
return vnull;
} public void setVnull(Object vnull) {
this.vnull = vnull;
} public String[] getAvString() {
return avString;
} public void setAvString(String[] avString) {
this.avString = avString;
} public int[] getAvint() {
return avint;
} public void setAvint(int[] avint) {
this.avint = avint;
} public boolean[] getAvboolean() {
return avboolean;
} public void setAvboolean(boolean[] avboolean) {
this.avboolean = avboolean;
} public List<String> getListString() {
return listString;
} public void setListString(List<String> listString) {
this.listString = listString;
} public Map<String, String> getMap() {
return map;
} public void setMap(Map<String, String> map) {
this.map = map;
} public Bar getBar() {
return bar;
} public void setBar(Bar bar) {
this.bar = bar;
} public Bar[] getAvBar() {
return avBar;
} public void setAvBar(Bar[] avBar) {
this.avBar = avBar;
} public List<Bar> getListBar() {
return listBar;
} public void setListBar(List<Bar> listBar) {
this.listBar = listBar;
}
}
package lavasoft.stu.json; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer; import java.util.Date;
import java.util.Random; /**
* Created by IntelliJ IDEA.
*
* @author leizhimin 11-11-22 上午9:15
*/
public class Bar {
public static SerializeConfig mapping = new SerializeConfig();
private String barName;
private int barAge;
private Date barDate = new Date();
static {
mapping.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd"));
}
{
Random r = new Random();
barName = "sss_"+String.valueOf(r.nextFloat());
barAge = r.nextInt();
} public static void main(String[] args) {
Object obj = JSON.toJSON(new Bar());
String x1 = JSON.toJSONString(new Bar(), true);
System.out.println(x1);
String x2 = JSON.toJSONString(new Bar(), mapping);
System.out.println(x2);
} public String getBarName() {
return barName;
} public void setBarName(String barName) {
this.barName = barName;
} public int getBarAge() {
return barAge;
} public void setBarAge(int barAge) {
this.barAge = barAge;
} public Date getBarDate() {
return barDate;
} public void setBarDate(Date barDate) {
this.barDate = barDate;
} @Override
public String toString() {
return "Bar{" +
"barName='" + barName + '\'' +
", barAge=" + barAge +
", barDate=" + barDate +
'}';
}
}
package lavasoft.stu.json; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer; import java.util.*; /**
* Created by 2IntelliJ IDEA.
*
* @author leizhimin 11-11-22 上午9:45
*/
public class Test {
private static SerializeConfig mapping = new SerializeConfig(); static {
mapping.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
} public static void main(String[] args) {
Foo f1 = new Foo();
Date date = new Date();
String text = JSON.toJSONString(date, mapping);
System.out.println(text);
System.out.println(JSON.toJSONString(f1, true));
String x2 =JSON.toJSONString(f1, mapping);
System.out.println(x2);
} public static void json2List(){
//List -> JSON array
List<Bar> barList = new ArrayList<Bar>();
barList.add(new Bar());
barList.add(new Bar());
barList.add(new Bar());
String json= JSON.toJSONString(barList, true);
System.out.println(json);
//JSON array -> List
List<Bar> barList1 = JSON.parseArray(json,Bar.class);
for (Bar bar : barList1) {
System.out.println(bar.toString());
}
} public static void json2Map(){
//Map -> JSON
Map<String,Bar> map = new HashMap<String, Bar>();
map.put("a",new Bar());
map.put("b",new Bar());
map.put("c",new Bar());
String json = JSON.toJSONString(map,true);
System.out.println(json);
//JSON -> Map
Map<String,Bar> map1 = (Map<String,Bar>)JSON.parse(json);
for (String key : map1.keySet()) {
System.out.println(key+":"+map1.get(key));
}
} public static void array2JSON(){
String[] arr_String = {"a","b","c"};
String json_arr_String = JSON.toJSONString(arr_String,true);
System.out.println(json_arr_String);
JSONArray jsonArray = JSON.parseArray(json_arr_String);
for (Object o : jsonArray) {
System.out.println(o);
}
System.out.println(jsonArray);
}
public static void array2JSON2(){
Bar[] arr_Bar = {new Bar(),new Bar(),new Bar()};
String json_arr_Bar = JSON.toJSONString(arr_Bar,true);
System.out.println(json_arr_Bar);
JSONArray jsonArray = JSON.parseArray(json_arr_Bar);
for (Object o : jsonArray) {
System.out.println(o);
}
System.out.println(jsonArray);
} public static void map2JSON(){
Map map = new HashMap();
map.put("a","aaa");
map.put("b","bbb");
map.put("c","ccc");
String json=JSON.toJSONString(map);
System.out.println(json);
Map map1 = JSON.parseObject(json);
for (Object o : map.entrySet()) {
Map.Entry<String,String> entry = (Map.Entry<String,String>)o;
System.out.println(entry.getKey()+"--->"+entry.getValue());
}
}
}
"2011-11-23 23:30:33"
{
"avBar":[{
"barAge":,
"barDate":,
"barName":"sss_0.62378174"
},{
"barAge":,
"barDate":,
"barName":"sss_0.36014742"
}],
"avString":["aaa","bbb","ccc"],
"avboolean":[true,false,true,true],
"avint":[,,,],
"bar":{
"barAge":,
"barDate":,
"barName":"sss_0.46644872"
},
"dddd":,
"listBar":[
{
"barAge":-,
"barDate":,
"barName":"sss_0.83562374"
},
{
"barAge":,
"barDate":,
"barName":"sss_0.59483266"
},
{
"barAge":,
"barDate":,
"barName":"sss_0.9961642"
}
],
"listString":[
"listString1",
"listString2",
"listString3"
],
"map":{"x":"s11111x","y":"s22222y","z":"s33333z"},
"v_Date":,
"vboolean":false,
"vbyte":,
"vchar":"x",
"vdouble":22.203,
"vfloat":12.1,
"vint":,
"vlong":,
"vshort":
}
{"avBar":[{"barAge":,"barDate":"2011-11-23 23:30:33","barName":"sss_0.62378174"},{"barAge":,"barDate":"2011-11-23 23:30:33","barName":"sss_0.36014742"}],"avString":["aaa","bbb","ccc"],"avboolean":[true,false,true,true],"avint":[,,,],"bar":{"barAge":,"barDate":"2011-11-23 23:30:33","barName":"sss_0.46644872"},"dddd":"2011-11-23 23:30:33","listBar":[{"barAge":-,"barDate":"2011-11-23 23:30:33","barName":"sss_0.83562374"},{"barAge":,"barDate":"2011-11-23 23:30:33","barName":"sss_0.59483266"},{"barAge":,"barDate":"2011-11-23 23:30:33","barName":"sss_0.9961642"}],"listString":["listString1","listString2","listString3"],"map":{"x":"s11111x","y":"s22222y","z":"s33333z"},"v_Date":"2011-11-23 23:30:33","vboolean":false,"vbyte":,"vchar":"x","vdouble":22.203,"vfloat":12.1,"vint":,"vlong":,"vshort":} Process finished with exit code
FastJSON应用前测试的更多相关文章
- FastJSON应用前测试--转载
FastJSON 应用前测试 FastJSON是一个很好的java开源json工具类库,相比其他同类的json类库,它的速度的确是fast,最快!但是文档做得不好,在应用前不得不亲测一些功能. ...
- IOS AppStore上线前测试
IOS AppStore上线前测试 TestFlight Beta ios 8才开始支持. https://developer.apple.com/library/ios/documentation ...
- 上线前测试的bug,要不要处理,跟版本的关系
最近有两个项目是在旧版本上实施的.上线前经过一轮测试后,发现了一些产品(我们的产品确实不稳定) 在这个项目上,修改产品bug是肯定的.但是要不要追踪这些bug? 这就跟版本使用范围有关系了,毕竟要考虑 ...
- 学生选课系统(Java语言期末前测试)
测试具体要求: 2.系统要求与功能设计 2.1 页面要求 (1)能够在Tomcat服务器中正确部署,并通过浏览器查看: (2)网站页面整体风格统一: (3)首页(登录页)要求实现不同用户登录后,进 ...
- 2017 6 2php用PDO链接数据库前测试
try { $dsn = "mysql:dbname=test;host=127.0.0.1";//链接mysql的DSN(数据库驱动) $user = 'root';//Mysq ...
- FastJSON 简介及其Map/JSON/String 互转
在日志解析,前后端数据传输交互中,经常会遇到 String 与 map.json.xml 等格式相互转换与解析的场景,其中 json 基本成为了跨语言.跨前后端的事实上的标准数据交互格式.应该来说各个 ...
- 关于xcode6打包以及上线前企业部署测试的说明 --转自张诚教授微博
xcode6如何打包 首先clean然后点击归档 点击打包之后保存 点选第一个以后检查相关证书签名 那么我们开发完以后,在上线前如何给别人测试 有2种方法 1.使用299美金的企业开发者账号搭建企业部 ...
- maven 打包前 Junit 测试
1. 在需要打包前测试的项目中添加依赖 <dependency> <groupId>junit</groupId> <artifactId>junit& ...
- [转]fastjson
原文地址:http://www.cnblogs.com/zhenmingliu/archive/2011/12/29/2305775.html FastJSON是一个很好的java开源json工具类库 ...
随机推荐
- vmware设置centos虚拟机nat联网(转)
今天在vmware虚拟主机中安装hearbeat,为了使用最新的版本,选用编译安装了.在编译过程中,需要连接被墙的网站下载文件,那只能用vpn,但我使用的是桥接方式联网,使用不了真实主机的vpn,于是 ...
- 使用PHP自动部署GIT代码
最近在使用Coding的代码托管,顺便设置了WebHook自动部署,过程还是挺艰辛的,主要还是没搞懂Linux的权限控制,不过好在弄好了,分享一下获益最深的一篇文章,供大家参考,原文是英文版的,我的英 ...
- Leetcode算法刷题:第100题 Same Tree
Same Tree 题目 给予两棵二叉树,判断这两棵树是否相等(即各节点的值都一样) 解题思路 分别遍历两棵二叉树,并用列表分别存储这两棵树的节点的值,比较这两个列表就可以了 class Soluti ...
- C语言--流程控制
一.流程控制 1.顺序结构 *默认的流程结构,按照书写顺序执行每一条语句 2.选择结构 *对给定的条件进行判断,再根据判断结果来决定执行那一段代码 3.循环结构 *在给定条件成立的情况下,反复执行某一 ...
- HDU 4121 Xiangqi
模拟吧,算是... 被这个题wa到哭,真是什么都不想说了...上代码 #include <iostream> #include <cstring> using namespac ...
- JS常见操作
//第一篇博文,希望大家多多支持 /***** BasePage.js 公共的 脚本文件 部分方法需引用jquery库 *****/ //#region 日期操作 //字符串转化为时间. functi ...
- SQL Server 存储过程自启动
前期准备: use master; create table LoginLog(LoginName nvarchar(32),LoginTime datetime); create procedure ...
- Oracle EBS-SQL (BOM-18):检查BOM与工艺路线对照.sql
/*有工艺路线,无BOM清单*/ select msi.segment1, msi.description from apps.BOM_OPERATIONAL_ROUTINGS bor, apps.m ...
- mybatis数据库数据分页问题
http://www.cnblogs.com/jcli/archive/2011/08/09/2132222.html 借花献佛,天天进步
- fabric 安装及使用
官网地址 1.安装 pip install fabric 依赖 Paramiko .PyCrypto库 以下依赖肯能要手动安装 #安装 pycrypto 密码库pip install pycrypto ...