2013-01-14 54 views
0

我有一個問題返回一個Json對象。 這是代碼。return Json(字典<int><int>) - > javascript

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 
    }); 
}); 

我的問題是「字典」沒有得到充斥着「數據」,我不能檢查,如果有一個在「數據」的任何值,因爲我可以在那裏設置一個斷點。

我發現已經有一個類似的問題here,但我不明白他在做什麼。

編輯: 我得到這個錯誤(我嘗試將它翻譯成英文): [ArgumentException的]:類型" System.Collections.Generic.Dictionary`2 [System.Int32,mscorlib程序,版本= 4.0。 0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089],[System.Int32,mscorlib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089]] " 將不支持字典的序列化/反序列化。 鍵必須是字符串或對象。

我會嘗試在對象中使用帶有兩個整數的列表。

+0

服務器端代碼的響應是什麼樣的? –

+0

我不知道如何檢查服務器端代碼。 dict對象看起來像一個數組,其中每個條目都有兩個名爲Key和Value的Int變量 – ndueck

+0

如果您找到解決方案,請將其作爲答案發布並接受它。不要在問題中寫下「已解決」。 ;) – bluish

回答

0

使用列表<列表< Int32 >>給我以下結果:[[82,193],[136,142],...]不如字典,但它的工作原理。

相關問題