将C#Hashtable值转换为List

时间:2015-09-07 06:59:03

标签: c# json post casting hashtable

我正在从Javascript向C#发送帖子请求

的Javascript

var name = "doe";
var ids = [1,2,3];

var parameter = {
ids : ids,
name : name,
groups: groups
}

C#

public string sampleMethod (Hashtable hashtable)
{
string name = hashtable["name"].toString();//works well
List<long> ids = (List<long>)hashtable["ids"];//doesnt work
}

我只想从哈希表中获取值[1,2,3] [&#34; ids&#34;]然后将其转换为long;

1 个答案:

答案 0 :(得分:0)

试试这个..

 Array ids = (Array)hashtable["ids"];

List<int> ids = (List<int>)hashtable["ids"]; 

 int[] ids = (int[])hashtable["ids"];