Computer Learning Zone CLZ Access Excel Word Windows

 
Home   Courses   Seminars   Templates   Help   TechHelp   Forums   Contact   Join   Order   Logon  
 
Tips & Tricks

New Tips Added Weekly!
Click here to get on our Mailing List

   
 
ASP

JSON

How to build a JSON Feed

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"
	

I tried this but didn't have much look.

	'Response.AddHeader('Content-Type', 'application/json')
	

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
	

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)
	

You also need to escape any slashes, so in URLS a / needs to be \/ so it renders correctly.

 

Alex Hedley (Avatar) By: Alex Hedley


Click here to sign up for more FREE tips

 

 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Account Login
Online Theater
Downloads
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Email Richard
Mailing Address
Phone Number
Fax Number
Course Survey
Blog RSS Feed    Twitter

YouTube Channel    LinkedIn