不同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 ...
随机推荐
- Codeforces Educational Codeforces Round 54 题解
题目链接:https://codeforc.es/contest/1076 A. Minimizing the String 题意:给出一个字符串,最多删掉一个字母,输出操作后字典序最小的字符串. 题 ...
- CF557E Ann and Half-Palindrome 字典树+dp
现在看这道题也不难啊,不知道考场上为啥没切~ code: #include <bits/stdc++.h> #define N 5006 #define setIO(s) freopen( ...
- 【概率论】3-7:多变量分布(Multivariate Distributions Part II)
title: [概率论]3-7:多变量分布(Multivariate Distributions Part II) categories: Mathematic Probability keyword ...
- CONTINUE...? ZOJ - 4033
CONTINUE...? ZOJ - 4033 题解:先计算一下总数sum是否是偶数,如果不是则不能分出来,如果是则从后面开始分,先把人分到1.3组,分完sum / 2这些人,如果恰好能够分成零,那么 ...
- 8月清北学堂培训 Day 7
当天走得太兴奋了,忘记保存就关电脑了o(╥﹏╥)o,现在补上( p′︵‵.) 今天是杨思祺老师的讲授~ 练习题 首先求出最短路: 如果选择的边不是最短路上的边,那么毫无影响: 对于最短路径上的边,我们 ...
- QtCreator集成的MSVC套件有问题
MSVC编译出来的内部签名算法的程序,相同的代码,验签结果和MINGW编译出来的不一样.MINGW编译出来的结果是正确的 怀疑是因为QtCreator集成的msvc有问题,可能是编码问题,可能是其他问 ...
- Open Live Writer 显示不出来代码着色插件解决办法
下载地址: Open Live Writer 插件更新 下载后要把下面这5个文件,全部解除锁定(右键属性打开) Memento.OLW.Plugins.dll OLWPlugins.css OpenL ...
- 表单事件集锦-input
最近在写一个手机端提交表单的项目,里面用了不少input标签,因为项目不太忙,所以,想做的完美点,但是遇到了一些问题,比如:页面中的必填项如果有至少一项为空,提交按钮就是不能提交的状态,所以需要对所有 ...
- Qt自定义委托在QTableView中绘制控件、图片、文字
自定义委托,继承于,QStyledItemDelegate类,重载Paint()函数, 1.实现在QTableView中绘制 格式字符串 2.实现在QTableView中绘制进度条 3.实现在QTab ...
- LC 986. Interval List Intersections
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order ...