json数据提取并使用ajax调用传递给C#

问题描述 投票:0回答:1

我有一个从IndexedDb数据源获取的json数据。当我做Json.stringify我得到的结果为

[{"key":1,"value":{"itemcode":"ItemA3","serialno":"erw33","saledate":"2020-05-03","id":1}},{"key":2,"value":{"itemcode":"ItemA4","serialno":"erewrwerwer","saledate":"2020-05-03","id":2}}]

我希望仅从此字符串中提取值部分,并使用ajax调用将其传递给带有数组args的c#函数。

 $.ajax({
            url: 'Export.aspx/GetDetails',
             type: 'POST',
             contentType: 'application/json; charset=utf-8',
             dataType: 'json',
             data: "{detls:" + serializedData + "}",
             success: function (r) {
                 alert("yes");
             },
             error: function (jqXHR, textStatus, errorThrown) {
                 alert(errorThrown);
             }
         });

c#函数是

[System.Web.Services.WebMethod]
public static string  GetDetails(string [] detls)
{
 //get  itemcode , serialno , saledate , id  
  return "s";
}

我收到内部服务器错误

c# asp.net json ajax indexeddb
1个回答
0
投票

使用value循环提取forEach

let serializedData = [];
dataFromIndexedDb.forEach(item => {
    serializedData.push(item.value);
});
alert(JSON.stringify(serializedData));

[dataFromIndexedDb是来自IndexedDb数据源的数据。

© www.soinside.com 2019 - 2024. All rights reserved.