gpt4 book ai didi

c# - 将数组从 JavaScript 传递到 C# 的最佳方式?

转载 作者:行者123 更新时间:2023-11-30 19:04:23 24 4
gpt4 key购买 nike

我需要将数组从 JavaScript 传递到 C# 中的页面方法。我试过在 IList 的 C# 方法中使用一个参数以及一个字符串 [] 数组。两种方式都抛出异常“cannot convert an object of type system.string to xxx”,其中xxx是C#方法中的参数类型。我将 jQuery 中的对象作为 json 对象传递,看起来它正在正常通过。这是它的样子:

{"testNumbers":"5555555555,3333333333,4444444444"}

我在这里做错了什么?

编辑:C# 代码:

[WebMethod()]
public static void ProcessAction(string[] testNumbers)
{
var dataProvider = new DataProvider();
dataProvider.ProcessAction(testNumbers);
}

最佳答案

嗯,两件事:

  1. JSON 数组周围有方括号
  2. 不引用 JSON 数字。

试试这个:

{"testNumbers": [5555555555,3333333333,4444444444]}

关于c# - 将数组从 JavaScript 传递到 C# 的最佳方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/296517/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com