【发布时间】:2013-01-14 13:42:15
【问题描述】:
我在返回 Json 对象时遇到问题。 这是代码。
public JsonResult getDictionary(List<Int32> input)
{
Dictionary<Int32, Int32> dict = new Dictionary<Int32, Int32>();
...fill dict
return Json(dict);
}
这是javascript代码
var dict = new Object();
...
$("#Button").click(function ()
{
var postData = { input: inputArray };
$.ajax({
type: "POST",
url: "/Auction/getDictionary",
data: postData,
success: function(data){
for(var i in data){
dict[i.Key] = i.Value;
}
//dict = data;
},
dataType: "json",
traditional: true
});
});
我的问题是“dict”没有被“data”填充,我无法检查“data”中是否有任何值,因为我无法在那里设置断点。
我已经找到了一个类似的问题here,但我不明白他在做什么。
编辑: 我收到此错误(我尝试将其翻译成英文): [ArgumentException]:类型“System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0。 0.0,文化=中性,PublicKeyToken=b77a5c561934e089]]" 将不支持字典的序列化/反序列化。 键必须是字符串或对象。
我会尝试在一个对象中使用一个包含两个整数的列表。
【问题讨论】:
-
服务器端代码的响应是什么样的?
-
我不知道如何检查服务器端代码。 dict 对象看起来像一个数组,每个条目上有两个名为 Key 和 Value 的 Int 变量
-
如果您找到了解决方案,请将其作为答案发布并接受。不要在问题中写“SOLVED”。 ;)
标签: dictionary jsonresult