ASP.NET Web API / ASP.NET MVC – JsonResult about Dictionary & Sorting
public JsonResult Get… …(… …) { return Json(… …); } |
Assume the Data Collection from the Server Side – Dictionary ( Key / Value ) is sorted by Value ( Expected ).
When Data Collection is returned from Server Side to JavaScript AJAX,
it would be enforced to be sorted by the JSON Object Key.
From Server Side ( Sequence ) : Key : 10, Value : AUSTRALIA … … Key : 1, Value : CHINA … … Key : 3, Value : HONG KONG |
From Client Side ( JavaScript AJAX ) : [ { 1 : "CHINA" }, { … … }, { 3 : "HONG KONG" }, … { 10 : "AUSTRALIA" } ] The Expected Sorting would be lost by using this Class Format ( Dictionary ) from Server Side to Client Side AJAX. |