0
我正在開發MVC 5中MIS的儀表板,並且在該儀表板中我想使用JVectorMap來加載已註冊的國家/地區。所以,以下是返回的JSON將數據從接收的JSON格式轉換爲JVectorMap格式
public JsonResult registeredCountries()
{
var ret = db.View_RegisteredCountries.Select(x => new { Key = x.CountryCode, Value = x.TotalCompanies }).ToDictionary(x => x.Key, x => x.Value).ToList();
return Json(ret, JsonRequestBehavior.AllowGet);
}
和下面是我的JS代碼來獲取JSON
var data = {};
$.ajax({
url: 'registeredCountries',
type: 'GET',
traditional: true,
async: false,
cache: false,
//async: false,
dataType: 'json'
}).done(function(result) {
data = result;
});
但我的問題是,JVectorMap使用數組的格式如下我的控制器行動
data_array = {
"US": 4977,
"AU": 4873,
"IN": 3671,
"BR": 2476,
"TR": 1476,
"CN": 146,
"CA": 134,
"BD": 100
};
但返回的JSON格式如下
[{ "Key": "SA", "Value": 4 }]
如何將上述JSON轉換爲以下格式,以便可以填充JVectorMap。
data_array = {
"SA":4
}