I am getting a JSON result in ASP Classic like this:
<script language="JScript" runat="server" src="json2.js"></script>
<%
Response.ContentType = "text/html"
Dim HttpReq
Dim Diamond
Set HttpReq = Server.CreateObject("Msxml2.ServerXMLHTTP.6.0")
HttpReq.open "GET", "http://url.com?id=" & Request.QueryString("id"), False
HttpReq.send
res = HttpReq.responseText
Set res = JSON.parse(res)
%>
It works.
Let’s say the JSON result will look like this:
res = {
gallery: {
image1: { img: 'source url', thumb: 'source url' },
image2: { img: 'source url', thumb: 'source url' },
image3: { img: 'source url', thumb: 'source url' }
},
another_param1: 'foo',
another param2: 'bar',
...
}
I want to then iterate the gallery object, not in JScript, but in VBScript.
How can I do that?
Thank you very much in advance.
If it is really necessary to enumerate an object’s properties in VBScript then you will need to convert the object to a dictionary. Here is a simple function that will take a JScript object and return
Scripting.Dictionary:With this function present in your page you can now convert the
galleryproperty to a dictionary:You can then iterate as:
Having said that its worth pointing out that properties named as a series like image1, image2 are a poor choice. It would be better if the JSON defined gallery as a simple array rather than an object. If you are in a position to influence the JSON design you should require that it be changed.