[英]C# Serialisation to jquery
我正在嘗試使用一些C#代碼填充javascript中的一些圖形數據
這是C#:
var publicationTable = new[] {
new[] { month.Select(x => Convert.ToDouble(x.RoomCount)).ToArray() },
new[] { month.Select(x => x.HoursCount).ToArray() }
};
return (new JavaScriptSerializer()).Serialize(publicationTable);
Javascript:
height: 375,
xGrid: false,
legend: true,
title: 'Meetings and Hours Used (Coming Soon!)',
points: <%= getJson() %>,
以下C#代碼有效:
public string getJson() {
var publicationTable = new[] {
new[] { 1, 2, 3, 4, 5 },
new[] { 6, 7, 8, 9, 10 }
};
return (new JavaScriptSerializer()).Serialize(publicationTable);
}
月是一個包含元素RoomCount(int)和HoursCount(Float)的列表
編輯說:看起來整個序列化都放在了圖形的第一個元素中(參見圖片)
你有沒有嘗試過:
var publicationTable = new[] {
month.Select(x => Convert.ToDouble(x.RoomCount)).ToArray(),
month.Select(x => x.HoursCount).ToArray()
};
.toArray()
已經返回一個數組,因此不需要new[]
(這樣,您可以創建一個數組,第一個元素是另一個數組)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.