我在这里已经看到了关于这个主题的几个问题,但似乎无法使用提供的方法正确显示我的完整日历,所以我希望有人可以帮我解决问题。
我的JSON Feed似乎填充正确,虽然我看到有人说它只适用于单引号,而其他只使用双引号。 (可能是围绕整个Feed的双引号问题?)
"[{"title":"change1","start":"2016-10-17T10:00:00","end":"2016-10-17T12:00:00","allDay":false},{"title":"change2","start":"2016-10-18T10:00:00","end":"2016-10-18T12:00:00","allDay":true},{"title":"change3","start":"2016-10-19T10:00:00","end":"2016-10-19T12:00:00","allDay":false}]"
calendar.aspx.cs:
public class Event
{
public string title;
public string start;
public string end;
public bool allDay;
}
[WebMethod]
public static string GetEvents()
{
var events = new List<Event>();
var sqlQuery = "SELECT title, starttime, endtime, allDay FROM [DeploymentDashboard].[dbo].[ChangeCalendar]";
using (var sqlConnection = new SqlConnection("Data Source=*server*;Initial Catalog=DeploymentDashboard;Integrated Security=True;"))
{
using (var cmd = new SqlCommand(sqlQuery, sqlConnection))
{
sqlConnection.Open();
using (var reader = cmd.ExecuteReader())
{
if (reader.HasRows)
{
while (reader.Read())
{
events.Add(new Event()
{
start = DateTime.Parse(reader["starttime"].ToString()).ToString("s"),
end = DateTime.Parse(reader["endtime"].ToString()).ToString("s"),
title = reader["title"].ToString(),
allDay = (bool)reader["allDay"]
});
}
}
}
sqlConnection.Close();
}
}
var theSerializer = new JavaScriptSerializer();
return theSerializer.Serialize(events);
}
calendar.aspx:
<script>
$(document).ready(function () {
$.ajax({
type: "POST",
url: "calendar.aspx/GetEvents",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json"
}).done(function (data) {
$('#calendar2').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
events: data.d
});
});
});
</script>
答案 0 :(得分:0)
试试这个:
%lf
答案 1 :(得分:0)
这应该解决它。
events: JSON.parse(data.d);
这有助于:https://www.w3schools.com/js/js_json_parse.asp
假设我们从Web服务器收到了以下文本:
'{“名称”:“约翰”,“年龄”:30,“城市”:“纽约”}'
使用JavaScript函数JSON.parse()将文本转换为 JavaScript对象:
var obj = JSON.parse('{“名称”:“约翰”,“年龄”:30,“城市”:“纽约”}');