我要創建這樣的:在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