常用的方法JSON.stringify(),JSON.parse()
1 JOSN.stringify(JsonObect) 这个函数是把Json对象转换成Json的字符串,如下
$.ajax({
type: "POST",
url: "../WebService/xxx.asmx/Save",
data: JSON.stringify({'jsonObject': 'hello'}),
contentType: "application/json; charset=utf-8",
dataType: "json",
error: function () { alert('error!'); },
success: function (response) { alert('save success!'); }
});
在ajax中使用json对象给服务器传值的时候,对Json对象进行处理,而不用自己拼凑Josn的字符串
2 JSON.parse(Jsonstring)与JSON.stringify正好相反,是把Json的字符串转换成Json的对象