By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,473 Members | 3,504 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,473 IT Pros & Developers. It's quick & easy.

jscript json used in vbscript?

P: n/a
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?
Jun 1 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Marc wrote:
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
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jun 1 '07 #2

P: n/a

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:O7**************@TK2MSFTNGP06.phx.gbl...
Marc wrote:
>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!!
Jun 1 '07 #3

P: n/a

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:O7**************@TK2MSFTNGP06.phx.gbl...
Marc wrote:
>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?

Jun 1 '07 #4

P: n/a
Marc wrote:
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

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jun 1 '07 #5

P: n/a
>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.
Okay, I thought so, thx
>
>I know how to do this in Javascript but am now stumped on that in
VbScript...

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

A javascript array is not a vbarray. They are different things. Google
for details
Okay, thx Bob!
Jun 1 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.