Jquery怎么将一个object对象转换成json字符串
5 回答

狐的传说
TA贡献1804条经验 获得超3个赞
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("失败,请稍后再试!");
}
});

不负相思意
TA贡献1777条经验 获得超10个赞
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 关注
- 2644 浏览
添加回答
举报
0/150
提交
取消