jscript json used in vbscript?

jscript json used in vbscript?

am 01.06.2007 14:37:38 von 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 %>

<%
Response.Write json.widget & "
"
For Each o In json.widget
Response.Write o.value & "
"
Next

Response.Write "IsArray: " & IsArray(json.widget) & "
"
Response.Write "IsObject: " & IsObject(json.widget) & "
"

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?

Re: jscript json used in vbscript?

am 01.06.2007 15:10:06 von reb01501

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 %>
>
> <%
> Response.Write json.widget & "
"
> For Each o In json.widget
> Response.Write o.value & "
"
> Next
>
> Response.Write "IsArray: " & IsArray(json.widget) & "
"
> Response.Write "IsObject: " & IsObject(json.widget) & "
"
>
> 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.

Re: jscript json used in vbscript?

am 01.06.2007 15:14:47 von marc

"Bob Barrows [MVP]" wrote in message
news:O7pFu4EpHHA.4532@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 %>
>>
>> <%
>> Response.Write json.widget & "
"
>> For Each o In json.widget
>> Response.Write o.value & "
"
>> Next
>>
>> Response.Write "IsArray: " & IsArray(json.widget) & "
"
>> Response.Write "IsObject: " & IsObject(json.widget) & "
"
>>
>> 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!!

Re: jscript json used in vbscript?

am 01.06.2007 16:21:20 von marc

"Bob Barrows [MVP]" wrote in message
news:O7pFu4EpHHA.4532@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 %>
>>
>> <%
>> Response.Write json.widget & "
"
>> For Each o In json.widget
>> Response.Write o.value & "
"
>> Next
>>
>> Response.Write "IsArray: " & IsArray(json.widget) & "
"
>> Response.Write "IsObject: " & IsObject(json.widget) & "
"
>>
>> 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 & "
"
Response.Write json.widget.[o] & "
"
Next

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

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

Re: jscript json used in vbscript?

am 01.06.2007 16:39:28 von reb01501

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 & "
"
> Response.Write json.widget.[o] & "
"
> 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.

Re: jscript json used in vbscript?

am 01.06.2007 16:42:44 von marc

>> 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!