jscript json used in vbscript?

M

Marc

I'm aware that there are significant differences between VBScript objects
and JScript objects but that doesn't mean something like the following
should give me such troubles?

<%@ Language=VBScript %>
<script language="jscript" runat="server">
var json = {"widget":[{"value":"text here"},{"value":123}]};
</script>
<%
Response.Write json.widget & "<br />"
For Each o In json.widget
Response.Write o.value & "<br />"
Next

Response.Write "IsArray: " & IsArray(json.widget) & "<br />"
Response.Write "IsObject: " & IsObject(json.widget) & "<br />"

Response.Write json.widget(0).value '<- won't work...?
%>

The above code return the following results:

[object Object],[object Object]
text here
123
IsArray: False
IsObject: True

Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method: 'widget'

/asp/json.asp, line 16


Anyone an idea how to get the dot notation:
json.widget(0).value
to work?
 
B

Bob Barrows [MVP]

Marc said:
I'm aware that there are significant differences between VBScript
objects and JScript objects but that doesn't mean something like the
following should give me such troubles?

<%@ Language=VBScript %>
<script language="jscript" runat="server">
var json = {"widget":[{"value":"text here"},{"value":123}]};
</script>
<%
Response.Write json.widget & "<br />"
For Each o In json.widget
Response.Write o.value & "<br />"
Next

Response.Write "IsArray: " & IsArray(json.widget) & "<br />"
Response.Write "IsObject: " & IsObject(json.widget) & "<br />"

Response.Write json.widget(0).value '<- won't work...?
%>

The above code return the following results:

[object Object],[object Object]
text here
123
IsArray: False
IsObject: True

Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method: 'widget'

/asp/json.asp, line 16


Anyone an idea how to get the dot notation:
json.widget(0).value
to work?

Like this:

Response.Write json.widget.[0].value
 
M

Marc

Bob Barrows said:
Marc said:
I'm aware that there are significant differences between VBScript
objects and JScript objects but that doesn't mean something like the
following should give me such troubles?

<%@ Language=VBScript %>
<script language="jscript" runat="server">
var json = {"widget":[{"value":"text here"},{"value":123}]};
</script>
<%
Response.Write json.widget & "<br />"
For Each o In json.widget
Response.Write o.value & "<br />"
Next

Response.Write "IsArray: " & IsArray(json.widget) & "<br />"
Response.Write "IsObject: " & IsObject(json.widget) & "<br />"

Response.Write json.widget(0).value '<- won't work...?
%>

The above code return the following results:

[object Object],[object Object]
text here
123
IsArray: False
IsObject: True

Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method: 'widget'

/asp/json.asp, line 16


Anyone an idea how to get the dot notation:
json.widget(0).value
to work?

Like this:

Response.Write json.widget.[0].value

I Almost fell of my chair...

I know I was thinking to do it like that but for some reason I thought:
nooo, that won't work...

Thx Bob!!
 
M

Marc

Bob Barrows said:
Marc said:
I'm aware that there are significant differences between VBScript
objects and JScript objects but that doesn't mean something like the
following should give me such troubles?

<%@ Language=VBScript %>
<script language="jscript" runat="server">
var json = {"widget":[{"value":"text here"},{"value":123}]};
</script>
<%
Response.Write json.widget & "<br />"
For Each o In json.widget
Response.Write o.value & "<br />"
Next

Response.Write "IsArray: " & IsArray(json.widget) & "<br />"
Response.Write "IsObject: " & IsObject(json.widget) & "<br />"

Response.Write json.widget(0).value '<- won't work...?
%>

The above code return the following results:

[object Object],[object Object]
text here
123
IsArray: False
IsObject: True

Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method: 'widget'

/asp/json.asp, line 16


Anyone an idea how to get the dot notation:
json.widget(0).value
to work?

Like this:

Response.Write json.widget.[0].value
--
btw
It does make me wonder how to know 'value'
I know how to do this in Javascript but am now stumped on that in
VbScript...

I tried :

For Each o In json.widget
Response.Write o.value & "<br />"
Response.Write json.widget.[o] & "<br />"
Next

but uhm... that's a no go...

and then... why isn't widget an Array?
 
B

Bob Barrows [MVP]

Marc said:
btw
It does make me wonder how to know 'value'

Do you mean you want to enumerate the object's property names? There is
no way to do that in vbscript.
I know how to do this in Javascript but am now stumped on that in
VbScript...

I tried :

For Each o In json.widget
Response.Write o.value & "<br />"
Response.Write json.widget.[o] & "<br />"
Next

but uhm... that's a no go...

and then... why isn't widget an Array?

A javascript array is not a vbarray. They are different things. Google
for details
 
M

Marc

btw
Do you mean you want to enumerate the object's property names? There is
no way to do that in vbscript.

Okay, I thought so, thx
A javascript array is not a vbarray. They are different things. Google
for details

Okay, thx Bob!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top