我需要将数组从 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);
}
最佳答案
嗯,两件事:
- JSON 数组周围有方括号
- 不引用 JSON 数字。
试试这个:
{"testNumbers": [5555555555,3333333333,4444444444]}
关于c# - 将数组从 JavaScript 传递到 C# 的最佳方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/296517/