我目前收到一个 json 响应,即:
[{"id":1,"title":"Test 1 "},{"id":2,"title":"Test 2"}]
我想将它转换为一个名为'events'的javascript数组,如下所示,以便我可以返回它:例如:
return {
events : [
{
"id":1,
"title":"Test 1"
},
{
"id":2,
"title":"Test 2"
}
]
};
我从 jquery ajax 调用中得到响应:
jQuery.ajax({
type: "POST",
url: "calendar.aspx/get_all_events",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
document.write(msg.d);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert('Error getting events from database.');
}
});
任何人都知道如何将 msg 或 msg.d 转换为需要的内容?
谢谢,