我要创建这样的:在Asp.Net Mvc中创建Json?
[
['date', 'T1', 'T2', 'T3'],
['2000', 1, 1, 0.5],
['2001', 2, 0.5, 1],
['2002', 4, 1, 0.5],
['2003', 8, 0.5, 1],
['2004', 7, 1, 0.5]
]
从我的模型
public partial class AylikOkumaIstatistik
{
public string sno { get; set; }
public string date{ get; set; }
public Nullable<decimal> TotalUsageValue { get; set; }
public string UsageType { get; set; } // T1,T2,T3
}
这是可能的使用JSON?如果可能,是否有关于这个主题的任何代码示例或教程。如何将数据库中的数据转换为json?
谢谢。
我新的关于这个话题,我使用mvc3。你能举个例子吗? – 2012-07-19 08:46:47
你可以使用Newtonsoft.Json(你可以通过NuGet下载)。只需使用JsonConvert.SerializeObject方法,您就可以将实体转换为json对象。查看相关主题:http://stackoverflow.com/questions/9729220/how-to-create-a-json-object-in-asp-net-mvc-3-controller。但我真的强烈建议你看看WebApi是最简单的方法,如果你的项目处于困境。 – 2012-07-19 08:52:28