How can I return a Dictionary as JsonResult, AND get the proper result in JavaScript?

后端 未结 1 531
灰色年华
灰色年华 2021-01-14 00:37

I\'m constructing my JsonResult in Controller by adding some extra information to an already existing JsonResult (returned from a different method). In order to add more pro

1条回答
  •  孤街浪徒
    2021-01-14 01:18

    Addendum: while writing the above question, it occurred to me that the translation between 'bad' array and 'good' array is indeed very simple:

        function translateAjaxResult(ret) {
            var result = new Array();
    
            if (ret == null) return result;
            for(var i = 0; i < ret.length; i++)
                result[ret[i].Key] = ret[i].Value;
            return result;
        }
    

    Nonetheless, it's still a patch to a problem and not a fix to a problem, so I'd still like a more elegant solution.

    0 讨论(0)
提交回复
热议问题