我有一个基于ASP.NET MVC编写的应用程序。在我的某个控制器中,我需要使用C#创建一个对象,以便使用JsonConvert.SerializeObject()
将其转换为JSON后结果如下:
[
{'one': 'Un'},
{'two': 'Deux'},
{'three': 'Trois'}
]
我尝试使用 Dictionary<string, string>
来实现以下功能:
var opts = new Dictionary<string, string>();
opts.Add("one", "Un");
opts.Add("two", "Deux");
opts.Add("three", "Trois");
var json = JsonConvert.SerializeObject(opts);
然而,上述操作会生成以下JSON。
{
'one': 'Un',
'two': 'Deux',
'three': 'Trois'
}
我该如何创建对象,以便JsonConvert.SerializeObject()
生成所需的输出?