JSONUtil.serialize(map)和JSON.toJSONString(map)的区别
数据库查询出来的map有一个字段为空
通过System.out.println()输出
JSONUtil.serialize(map): {"one":"1","two":"null","three":"3","four":"4","five":"5"}
JSON.toJSONString(map): {"one":"1","three":"3","four":"4","five":"5"}
JSON.toJSONString(map): {"one":"1","three":"3","four":"4","five":"5"}
jsp页面
Js的eval()方法:
var jsonObj = eval("("+jsonStr+")");
//如果使用JSONUtil.serialize(map)可以输出空串,如果是JSON.toJSONString(map)会报错
jsonObj.two;
jquery-1.9.1.js的val()源码如下
val: function( value ) { var ret, hooks, isFunction, elem = this[0]; if ( !arguments.length ) { if ( elem ) { hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ]; if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) { return ret; } ret = elem.value; return typeof ret === "string" ? // handle most common string cases ret.replace(rreturn, "") : // handle cases where value is null/undef or number ret == null ? "" : ret; } return; }