- 1 var a = {} 与 var a = function(){} 区别
var a = {}
此时a是一个对象,是一个没有任何属性的对象。
var a = {‘name’:’object’}
此时a是一个对象,是一个有一个属性的对象,属性名为name,属性的值为object。
alert(a.name) 或者alert(a[name])的结果都是object,这是对象访问属性的两种方式。
var a = function(){}
此时a指向一个函数,相当于有一个函数,名为a,可以这么调用这个函数:
a()
只不过这个函数什么都没有做。
var a = function(){
alert(1);
}
此时a是一个函数,调用a()执行的是函数体,也就是 alert(1)
就这样了,没什么不正常的吧。
- 2 JSON.stringify() 方法
JSON.stringify() 方法用于将 JavaScript 值转换为 JSON 字符串。
语法
JSON.stringify(value[, replacer[, space]])
参数说明:
value:
必需, 要转换的 JavaScript 值(通常为对象或数组)。
replacer:
可选。用于转换结果的函数或数组。
如果 replacer 为函数,则 JSON.stringify 将调用该函数,并传入每个成员的键和值。使用返回值而不是原始值。如果此函数返回 undefined,则排除成员。根对象的键是一个空字符串:”“。
如果 replacer 是一个数组,则仅转换该数组中具有键值的成员。成员的转换顺序与键在数组中的顺序一样。当 value 参数也为数组时,将忽略 replacer 数组。
space:
可选,文本添加缩进、空格和换行符,如果 space 是一个数字,则返回值文本在每个级别缩进指定数目的空格,如果 space 大于 10,则文本缩进 10 个空格。space 有可以使用非数字,如:\t。
-
3 JSON 数组完整的 jsp 传值,action 接值
.ajax({
url:’./service/iposremoteapprove/caseToUser.do’,
data:{
ds:JSON.stringify(data) /* 特别需要注意这里,需要现将json数组通过JSON.stringify()处理一下之后,才能作为我们需要的参数传过去
},
type:’post’,
dataType:”json”,
success:function(json){ .ajax({ url:’./service/iposremoteapprove/caseToUser.do’, data:{ ds:JSON.stringify(data) /* 特别需要注意这里,需要现将json数组通过JSON.stringify()处理一下之后,才能作为我们需要的参数传过去 }, type:’post’, dataType:”json”, success:function(json){ .messager.alert(“提示”,”成功”,”info”);
}
});
java接收参数
String ds = request.getParameter(“ds”);
JSONArray json=JSONArray.fromObject(ds);
JSONObject jsonOne;
Map