Jquery怎么将一个object对象转换成json字符串
5 回答
MMMHUHU
TA贡献1834条经验 获得超8个赞
var obj = {};
obj.projectID = $("#list").val();
……
$.ajax({
type: "POST",
contentType: "application/json;utf-8",
url: "/Task/Creat",
dataType: "text",
data: "json=" + jQuery.toJSON(obj) + "&id=0",
success: function (data) {
……
},
error: function () {
alert("失败,请稍后再试!");
}
});
慕村9548890
TA贡献1884条经验 获得超4个赞
1 2 3 4 5 6 7 8 9 10 11 | <script> //对象转json var data = {"user":[{"name":"John1","pwd":"123"},{"name":"John2","pwd":"1233"}]}; var json_str = JSON.stringify(data); alert(json_str);
//json字符串转对象 var userObj='{"user":[{"name":"John","pwd":"123"}]}'; var json = $.parseJSON(userObj); alert(json.user[0].name); </script> |
- 5 回答
- 0 关注
- 2084 浏览
添加回答
举报
0/150
提交
取消