我正在使用这个字符串:
{"0":{"title":"iPhone"},"1":{"title":"iPod"},"2":{"title":"iPad"},"length":3,"prevObject":{"0":{},"1":{},"2":{},"length":3,"prevObject":{"0":{},"length":1,"context":{"location":{},"jQuery18308480830912211994":1},"selector":"#mycart"},"context":{"location":{},"jQuery18308480830912211994":1},"selector":"#mycart li"},"context":{"location":{},"jQuery18308480830912211994":1}}
我想清除这个字符串,并相应地生成一个<List>
包含 3 个项目的或数组: Iphone iPod Ipad 我产生上述内容的代码是:
$("#btngetCart").live("click", function () {
var items = $('#mycart').find('li').map(function () {
var item = {};
item.title = $(this).text();
return item;
});
var json = JSON.stringify(items);
$.ajax({
type: 'POST',
url: "WebForm5.aspx/GetCart",
data: "{item:" + JSON.stringify(json) + "}",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (r) {
}
});
});
以及后面的代码:
[WebMethod(EnableSession = true)]
public static string GetCart(string item)
{
HttpContext.Current.Session["f"] = item;
return item;
}