ASP Parsing JSON Example

Source: Internet
Author: User
Tags object end eval json

JSON (Object notation) I think this name is not unfamiliar to everyone, it is a lightweight data interchange format, is directly generated by the service of the statement, the client is obtained directly with the Eval method to obtain this object, so you can save parsing XML Parsing brings performance issues and compatibility issues, and is very easy to use, you can easily traverse the array and access to object properties to obtain data, its readability is also good, basically have the nature of structured data. Have to say is a good way, for example, Google Maps did not use XML to pass data, but use the JSON scheme.

Here I give you an ASP call Json example, play a role in the ...

Here is the tset.asp code fragment


<%
Dim strtest
Strtest = "{name:" "alonely" ", Age:24, email:[" "ycplxl1314@163.com" "," "ycplxl1314@gmail.com" "], family:{parents:[" " Father "", "" Mother ""],tostring:function () {return "" family member "";}}} "
Dim Objtest
Initscriptcontrol
Set objtest = Getjsonobject (strtest)
%>
<%=objTest.name%> Email address is <%=sc4json.eval ("jsonobject.email[0]")%>

Total Email address <%=objTest.email.length%>

<%
Dim father
Getjsarrayitem father, objTest.family.parents, 0
Response.Write Father
%>

Here is the jsonparse.asp code fragment

<%
Option Explicit
Dim Sc4json
Sub Initscriptcontrol
Set Sc4json = Server.CreateObject ("Msscriptcontrol.scriptcontrol")
Sc4json.language = ""
Sc4json.addcode "var itemtemp=null;function getjsarray (arr, index) {Itemtemp=arr[index];}"
End Sub
Function Getjsonobject (Strjson)
Sc4json.addcode "var jsonobject =" & Strjson
Set Getjsonobject = Sc4Json.CodeObject.jsonObject
End Function
Sub Getjsarrayitem (objdest, Objjsarray, index)
On Error Resume Next
Sc4json.run "Getjsarray", Objjsarray, Index
Set objdest = sc4Json.CodeObject.itemTemp
If err.number=0 Then
Exit Sub
End If
Objdest = Sc4Json.CodeObject.itemTemp
End Sub
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.