不同Json工具对空串和NULL的序列号处理:net.sf.json 和 fastjson
net.sf.json 和 fastjson 对于空串和NULL的处理:
1、测试代码
package com.TestMain;
import com.alibaba.fastjson.JSON;
import java.util.HashMap;
import java.util.Map;
public class TestTest {
public static void main(String args[]) throws Exception {
String sDesc = "";
Map<String, String> map = new HashMap<String, String>();
map.put("test", "test");
map.put("str", null);
System.out.println("测试:null");
System.out.println("ALIBAB:"+JSON.toJSONString(map));
System.out.println("net:"+net.sf.json.JSONObject.fromObject(map).toString());
System.out.println("=====");
Map<String, String> map2 = new HashMap<String, String>();
map2.put("test", "test");
map2.put("str", "null");
System.out.println("测试:null字符串");
System.out.println("ALIBAB:"+JSON.toJSONString(map2));
System.out.println("net:"+net.sf.json.JSONObject.fromObject(map2).toString());
System.out.println("=====");
Map<String, String> map3 = new HashMap<String, String>();
map3.put("test", "test");
map3.put("str", "");
System.out.println("测试:空白字符串");
System.out.println("ALIBAB:"+JSON.toJSONString(map3));
System.out.println("net:"+net.sf.json.JSONObject.fromObject(map3).toString());
System.out.println("=====");
}
}
2、测试结果:
测试:null
ALIBAB:{"test":"test"}
net:{"str":null,"test":"test"}
=====
测试:null字符串
ALIBAB:{"str":"null","test":"test"}
net:{"str":null,"test":"test"}
=====
测试:空白字符串
ALIBAB:{"str":"","test":"test"}
net:{"str":"","test":"test"}
=====
3、总结:
- fastJson 根据传入的对象进行序列化,是字符串就是字符串,是NULL就是NULL。序列化结果不包含NULL。
- net.sf.json 会将NULL和NULL字符串都作为NULL处理。序列化结果包含NULL,但是其值也是NULL(不是NULL字符串)。
4、注:Maven中引入net.sf.json的方式
不同Json工具对空串和NULL的序列号处理:net.sf.json 和 fastjson的更多相关文章
- Json工具类,实现了反射将整个Object转换为Json对象的功能,支持Hibernate的延迟加
package com.aherp.framework.util; import java.lang.reflect.Array;import java.lang.reflect.Method;imp ...
- net.sf.json.JSONOBJECT.fromObject 与 com.alibaba.fastjson.JSONObject.parseObject
文章待补充,先写写以下知识点好了. NULL值处理之 net.sf.json.JSONObject 和 com.alibaba.fastjson.JSONObject区别 JSON作为一个轻量级的文本 ...
- net.sf.json.JSONException: java.lang.NoSuchMethodException
在尝试将json对象转换为list时候出现了如下错误 Exception in thread "main" net.sf.json.JSONException: java.lang ...
- net.sf.json.JSONException: There is a cycle in the hierarchy!
因为项目中使用了AJAX技术,jar包为:json-lib.jar,在开发过程中遇到了一个JSON-LIB和Hibernate有关的问题: 如hibernate延迟加载错误,这都是些老问题了,一看就知 ...
- net.sf.json
JSONObject package com.itlwc.test; import net.sf.json.JSONArray; import net.sf.json.JSONO ...
- 解析json方式之net.sf.json
前面转载了json解析的技术:fastjson,今天说下另外一种技术. 下载地址 本次使用版本:http://sourceforge.net/projects/json-lib/files/json- ...
- net.sf.json.JSONException: There is a cycle in the hierarchy!错误解决方案
net.sf.json.JSONException: There is a cycle in the hierarchy!错误解决方案 今天在用List集合转换成json数组的时候发生了这个错误,这个 ...
- Code片段 : .properties属性文件操作工具类 & JSON工具类
摘要: 原创出处:www.bysocket.com 泥瓦匠BYSocket 希望转载,保留摘要,谢谢! “贵专” — 泥瓦匠 一.java.util.Properties API & 案例 j ...
- 分享一个关于jackson的Json工具类
直接贴代码: import org.codehaus.jackson.map.DeserializationConfig.Feature; import org.codehaus.jackson.ma ...
随机推荐
- deferred.pipe([doneFilter],[failFilter],[progressFilter])
deferred.pipe([doneFilter],[failFilter],[progressFilter]) 概述 筛选器和/或链Deferreds的实用程序方法. deferred.pipe( ...
- Excel2013下拉框选择自动填充颜色
图一写判断公式,图二选择应用范围.
- 关系型数据库与NoSQL的对比
SQL(结构化的查询语言)数据库是过去四十年间存储数据的主要方式.20世纪90年代末随着Web应用和MySQL.PostgreSQL和SQLite等开源数据库的兴起,用户爆炸式的增长. NoSQL数据 ...
- Gym - 102307G Graduation 拓扑排序
Gym - 102307G Graduation 题意:xjl得修够n门课才能毕业,其中有些课是某门课的先行课,并且他精力有限,每学期最多只能修k门课,问xjl最少需要多少学期才能毕业. 首先,正向 ...
- 【线性代数】6-6:相似矩阵(Similar Matrices)
title: [线性代数]6-6:相似矩阵(Similar Matrices) categories: Mathematic Linear Algebra keywords: Similar Matr ...
- Python2.7编码问题:UnicodeDecodeError: 'ascii' codec can't decode byte 0xe8 in position...解决方法
解决方法: 在Python程序最前面加上以下语句: import sys reload(sys) sys.setdefaultencoding('utf-8')
- idea 2018注册码(激活码)
最近做一个项目,用idea 社区版的 但是缺少了好多功能 无奈只能用专业版的,但是需要注册激活 下面是我的注册方法 1.打开了idea 会提示让激活 选择Licensse server 2. ...
- Programming a Hearthstone agent using Monte Carlo Tree Search(chapter one)
Markus Heikki AnderssonHåkon HelgesenHesselberg Master of Science in Computer Science Submission dat ...
- linux下的usb抓包方法
1 linux下的usb抓包方法1.配置内核使能usb monitor: make menuconfig Device Drivers --> ...
- Android自定义控件之基本图形绘制
入门示例代码 在Android中Paint类就是画笔,Canvas 就是画布 对于画笔的大小,粗细,颜色,透明度都在paint类中设置,对于画出的成品,比如圆,方形,等在canvas类中的函数生成 入 ...