不同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 ...
随机推荐
- 从package.json中获取属性
var pjson = require('./package.json'); console.log(pjson.version); 详见:https://stackoverflow.com/ques ...
- Educational Codeforces Round 67 (Rated for Div. 2) B题【前缀+二分】【补题ING系列】
题意:给出一个字符串s, 可以从左往右拿走s的字符, 至少要到s的第几个位置才能拼成t 思路:用二维数组记录前缀,然后二分即可. #include<bits/stdc++.h> using ...
- mouseup([[data],fn])
mouseup([[data],fn]) 概述 当在元素上放松鼠标按钮时,会发生 mouseup 事件. 与 click 事件不同,mouseup 事件仅需要放松按钮.当鼠标指针位于元素上方时,放松鼠 ...
- 003_linux之点灯(C语言版)
linux点灯在汇编版中说明了硬件中点灯的原理,C语言中不再陈述,说白了就是控制GPXCON和GPXDTA寄存器就行了,芯片是S3C2440A芯片,查看芯片手册就能懂了,其他芯片也是一样的.C语言版就 ...
- 运算符重载之new与delete
关于new/delete,援引C++ Primer中的一段话: 某些应用程序对内存分配有特殊的要求,因此我们无法直接将标准的内存管理机制直接应用于这些程序.他们常常需要自定义内存分配的细节,比如使用关 ...
- 解决ScrollView中Recyclerview显示不全,滑动不流畅的问题
这个问题经常会碰到,看了下网上关于这个问题的解决方案,有很多都是复制粘贴的,并不能根本解决问题 比较有效的一种方案是在Recyclerview的外层套一个RelativeLayout 然后设置recy ...
- pycham更换主题
在pycham的file-->Setting-->Editor-->Colors&Fonts
- CTF辅助脚本
首先推荐这篇文章,网上有多次转载,这是我见过日期比较早的 CTF中那些脑洞大开的编码和加密 凯撒密码 flag='flag{abcdef}' c='' n=20 for i in flag: if ' ...
- Resend a Request by fiddler
Resend a Request You can resend a request directly from the Sessions List, or save requests to resen ...
- 【Java/JDBC】借助ResultSetMetaData,从数据库表中抽取字段信息存成Excel文件
本例工程下载:https://files.cnblogs.com/files/xiandedanteng/FindNotnullColumns20191102-3.rar 工作中曾有个为42张表建立测 ...