Question

i've got a problem returning a Json object. Here's the code.

 public JsonResult getDictionary(List<Int32> input)
 {
    Dictionary<Int32, Int32> dict = new Dictionary<Int32, Int32>();
    ...fill dict
    return Json(dict);
 }

Here's the javascript code

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

My Problem is "dict" doesn't get filled with "data" and i can't check if there's any value in "data" because i can't set a breakpoint there.

I've found already a similiar question here, but i don't understand what he is doing.

EDIT: I get this Error (i try to translate it to english): [ArgumentException]: The Type "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, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" will not be supported for the serialisation/deserialisation for a dictionary. Keys have to be Strings or Objects.

I will try using a List with two integer in an object.

Was it helpful?

Solution

Using a List< List< Int32>> gives me following result: [[82,193],[136,142], ... ] Not as good as a Dictionary but it works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top