I'm trying to format my web service result (JSON) to look like the mentioned example. With this current format FullCalendar is not able to display my events.
If you look at my output you will see that the date format is different from the example even though I tried not to use (ToUnixTimespan) and I have double quotes on every item such as, title,start,end and id.
How can I get rid of those double quotes and format the date and time?
I appreciate your efforts in reaching a solution for my problem.
EXAMPLE
events: [
{
title: 'All Day Event',
start: '2014-11-01'
},
{
title: 'Long Event',
start: '2014-11-07',
end: '2014-11-10'
},
{
id: 999,
title: 'Repeating Event',
start: '2014-11-09T16:00:00'
},
{
id: 999,
title: 'Repeating Event',
start: '2014-11-16T16:00:00'
},
{
title: 'Conference',
start: '2014-11-11',
end: '2014-11-13'
},
{
title: 'Meeting',
start: '2014-11-12T10:30:00',
end: '2014-11-12T12:30:00'
},
{
title: 'Lunch',
start: '2014-11-12T12:00:00'
},
{
title: 'Meeting',
start: '2014-11-12T14:30:00'
},
{
title: 'Happy Hour',
start: '2014-11-12T17:30:00'
},
{
title: 'Dinner',
start: '2014-11-12T20:00:00'
},
{
title: 'Birthday Party',
start: '2014-11-13T07:00:00'
},
{
title: 'Click for Google',
url: 'http://google.com/',
start: '2014-11-28'
}
]
My output looks like this
[
{
"id": 10,
"start": 1427094900,
"end": 1427185800,
"title": "new"
},
{
"id": 11,
"start": 1426978800,
"end": 1427065200,
"title": "hi"
},
{
"id": 12,
"start": 1427094000,
"end": 1427181300,
"title": "hi2"
},
{
"id": 13,
"start": 1427094900,
"end": 1427100300,
"title": "test"
},
{
"id": 14,
"start": 1427094000,
"end": 1427184900,
"title": "Al"
},
{
"id": 15,
"start": 1427698800,
"end": 1427710500,
"title": "CalTest"
}
]
My Class file
Public Class CalendarDTO
Private m_id As Int32
Public Property id() As Int32
Get
Return m_id
End Get
Set(ByVal value As Int32)
m_id = value
End Set
End Property
Private m_Start As Int64
Public Property start() As Int64
Get
Return m_Start
End Get
Set(ByVal value As Int64)
m_Start = value
End Set
End Property
Private m_End As Int64
Public Property [end]() As Int64
Get
Return m_End
End Get
Set(ByVal value As Int64)
m_End = value
End Set
End Property
Private m_Title As String
Public Property title() As String
Get
Return m_Title
End Get
Set(ByVal value As String)
m_Title = value
End Set
End Property
'Private m_allday As String
'Public Property allDay() As String
' Get
' Return m_allday
' End Get
' Set(ByVal value As String)
' m_allday = value
' End Set
'End Property
End Class
My web service
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Data.SqlClient
Imports System.Web.Script.Serialization
<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://someurl/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class Calendar
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function EventList() As String
Dim events As New List(Of CalendarDTO)
Dim comm1 As SqlCommand
Dim conn1 As SqlConnection
Dim reader1 As SqlDataReader
Dim connectionString1 As String = ConfigurationManager.ConnectionStrings("CalTest").ConnectionString
conn1 = New SqlConnection(connectionString1)
comm1 = New SqlCommand("SELECT [id],[title] ,[description],[start] ,[end] ,[allday] FROM [CalTest].[dbo].[event]", conn1)
conn1.Open()
reader1 = comm1.ExecuteReader()
While reader1.Read()
Dim value As CalendarDTO = New CalendarDTO()
value.id = reader1("id").ToString()
value.title = reader1("title").ToString()
value.start = ToUnixTimespan(reader1("start").ToString())
value.end = ToUnixTimespan(reader1("end").ToString())
events.Add(value)
End While
reader1.Close()
conn1.Close()
Dim js As New System.Web.Script.Serialization.JavaScriptSerializer
Return js.Serialize(events)
End Function
Private Function ToUnixTimespan(ByVal d As DateTime) As Int64
Dim time As New TimeSpan()
time = d.ToUniversalTime().Subtract(New DateTime(1970, 1, 1, 0, 0, 0))
Return CType(Math.Truncate(time.TotalSeconds), Int64)
End Function
Private Function FromUnixTimespan(ByVal s As String) As DateTime
Dim time As DateTime = New DateTime(1970, 1, 1, 0, 0, 0)
Return time.AddSeconds(s)
End Function
End Class