You can use a Dictionary<string, Dictionary<string, string>> to create the JSON. First set up the dictionary with the data you want, then return it from your MVC controller using the Json() method like this:
public ActionResult GetMyJson()
{
var dict = new Dictionary<string, Dictionary<string, string>>()
{
{
"1", new Dictionary<string, string>()
{
{ "1年期", "12" },
{ "13個月期", "13" },
{ "2年期", "24" },
{ "3年期", "36" },
}
},
{
"2", new Dictionary<string, string>()
{
{ "1年期", "12" },
{ "13個月期", "13" },
{ "2年期", "24" },
{ "3年期", "36" },
}
},
{
"3", new Dictionary<string, string>()
{
{ "1個月期", "1" },
{ "3個月期", "3" },
{ "6個月期", "6" },
{ "9個月期", "9" },
{ "1年期", "12" },
{ "13個月期", "13" },
{ "2年期", "24" },
{ "3年期", "36" },
}
}
};
return Json(dict);
}
Alternatively, you can serialize the dictionary using Json.Net like this:
string json = JsonConvert.SerializeObject(dict, Formatting.Indented);
But if you do it this way, and you want to return the JSON from inside an MVC controller, you will need to use the Content() method instead:
return Content(json, "application/json");