JSON
In this tutorial you will learn how to create a JSON feed.
You need to make sure the page returns the correct Content Type. Add this as the first line.
Response.ContentType = "application/json"
Copy
I tried this but didn't have much look.
'Response.AddHeader('Content-Type', 'application/json')
Copy
I also added some Formatting changes to the data.
Function ApplyFormatting(strInput)
strInput = Replace(strInput, Chr(13) , " ") 'vbCr
strInput = Replace(strInput, Chr(10) , " ") 'vbCrLf
'vbNewline vbLf vbTab \n
ApplyFormatting = strInput
End Function
Copy
There was also a need to remove the last comma (,) at the end of the ITEMS array. So I created a String, appended each item to that then at the end removed the last one.
You could connect to a Database and loop through a RecordSet.
Dim strItems
strItems = ""
If NOT rs.EOF Then rs.MoveFirst
While NOT rs.EOF
strItems = strItems & "{"
strItems = strItems & " ""id"" : " & ApplyFormatting(rs("BlogID")) & " "
strItems = strItems & ","
'Add any other items
strItems = strItems & "}"
strItems = strItems & ","
'POST End
'Repeat more Posts
rs.MoveNext
'Loop
Wend
' Remove the last ","
strItems = Left(strItems, len(strItems)-1)
Response.Write(strItems)
Copy
You also need to escape any slashes, so in URLS a / needs to be \/ so it renders correctly.
Pre-Requisite
Members
No members extras today
Recommended Courses
Details
In this tutorial you will learn how to create a JSON feed.
Keywords
#asp, #classicasp, #help, #howto, #tutorial, #learn, #lesson, #training, #webdesign, #VBScript, classic ASP
Legacy