我正在尝试将一个id列表发送给一个通用处理程序,该处理程序将处理这些ID并执行进一步的逻辑。我发送了items: ["32", "33"]
等ID列表。我无法获得这些物品的ID。我试图序列化,反序列化并将值放在一个对象中而没有任何运气。你能帮我看看我在这个过程中出错了吗?
============ JavaScript ==============
$.ajax({
type: "post",
data: JSON.stringify({ 'items': itemIds }),
url: 'deleteItems.ashx',
success: function (data) {
console.log('working');
console.log(data);
},
error: function (request, err) {
console.log(err);
}
});
=============从console.log中的delteItems.ashx返回的数据=============
" items":[
" 39"
] {"项目":[" 39"]}
============ DeleteItems.ashx =================
//not sure if this is needed
public class inventoryItems
{
public List<string> items { get; set; }
}
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string json = new StreamReader(context.Request.InputStream).ReadToEnd();
//iif I use a list in DeserializeObject with the inventoryItems class, I return an error in my ajax file.
dynamic inventoryItems = JsonConvert.DeserializeObject(json);
foreach (var obj in inventoryItems)
{
context.Response.Write(obj);
// return each id and do more logic
}