Learning is not attained by chance, it must
be sought for with ardor and diligence.
-Abigail Adams
 
Home   News   Courses   Tips   Templates   Forums   Help   Order   Contact   Logon  
 
NEW: Excel Expert 11 - Learn XLOOKUP    dismiss
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

 

You may want to read these articles from the 599CD News:

 

Learn
 
Accessindex
Excelindex
Wordindex
Windowsindex
PowerPointindex
Photoshopindex
Visual Basicindex
ASPindex
Seminars
More...
Customers
 
Account Login
Online Theater
Downloads
Lost Password
Free Upgrades
Insider Circle
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Articles
Search The Site
Waiting List
Production Schedule
Collapse Menus
Help
 
Live Chat
Customer Support
WalkThru Tutorials
Troubleshooting
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Order
 
Video Tutorials
Handbooks
MYOLP Memberships
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Gift CDs
Contact
 
Live Chat
General Info
Support Policy
Contact Form
Email Richard
Mailing Address
Phone Number
Fax Number
Course Survey
Facebook    Twitter

YouTube Channel    LinkedIn

Blog RSS Feed