I started learning the use of JSON in ASP some time ago. JSON is indeed more convenient than XML. I used to consider using XML to store data when I was writing programs, but I always found it troublesome to generate documents and call and query documents. And when you want to use a certain node, you need to analyze it carefully and position the path of the node level by level. The biggest advantage of JSON is that when using it, you only need to declare the data string as an object, and you can easily call each member of the object. It is also convenient to use Javascript on the client to directly call the data string generated by the program.
Anyone who uses ASP knows that ASP can use two types of script engines, namely VBSCRIPT and JSCRIPT. I didn't know JSCRIPT at all when I first started studying. If I had known it, I think I wouldn't have to go through such trouble to convert the JSON data into JSCRIPT before it can be used in VBSCRIPT. Fortunately, both script engines have their own advantages and disadvantages, and I have been working with VBSCRIPT for more than two years. Although it is not strong, I have become accustomed to some of its usage methods and have formed my own code output specifications. .
The official JSON class file is very convenient, and you can flexibly define and output the JSON data format you want. I sorted out the official class files and adjusted them into a format that I find very convenient!
Adjusted JSON class file, code file address:
ASP Json class file source code
Code usage examples:
1. Create a JSON object
Copy the code code as follows:
Set CNodeJson=New Json_Cls
CNodeJson.QuotedVars=false 'Whether the object name is in quotes
CNodeJson(ID)=1
CNodeJson(Name)=Cloud.L
CNodeJson(BlogName)=Cloud.L Blog
SetCNodeJson=Nothing
2. Create another object within the object
Copy the code code as follows:
Set CNodeJson=New Json_Cls
CNodeJson.QuotedVars=false 'Whether the object name is in quotes
CNodeJson(ID)=1
CNodeJson(Name)=Cloud.L
CNodeJson(BlogName)=Cloud.L Blog
Set CNodeJson(SiteList)=New Json_Cls
CNodeJson(SiteList)(Blog)=http://www.vevb.com
CNodeJson(SiteList)(CSDN)=http://hi.csdn.net/lingyun410
SetCNodeJson=Nothing