jscript json used in vbscript?

Discussion in 'ASP General' started by Marc, Jun 1, 2007.

  1. Marc

    Marc Guest

    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?
     
    Marc, Jun 1, 2007
    #1
    1. Advertising

  2. 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.
     
    Bob Barrows [MVP], Jun 1, 2007
    #2
    1. Advertising

  3. Marc

    Marc Guest

    "Bob Barrows [MVP]" <> wrote in message
    news:...
    > 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!!
     
    Marc, Jun 1, 2007
    #3
  4. Marc

    Marc Guest

    "Bob Barrows [MVP]" <> wrote in message
    news:...
    > 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?
     
    Marc, Jun 1, 2007
    #4
  5. 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.
     
    Bob Barrows [MVP], Jun 1, 2007
    #5
  6. Marc

    Marc Guest

    >> 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!
     
    Marc, Jun 1, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon Maz
    Replies:
    4
    Views:
    1,277
    Jon Maz
    Sep 9, 2004
  2. Maxwell2006
    Replies:
    5
    Views:
    2,399
    Steven Cheng[MSFT]
    Mar 7, 2006
  3. Florian Frank
    Replies:
    0
    Views:
    244
    Florian Frank
    Jun 30, 2009
  4. John Bentley
    Replies:
    14
    Views:
    353
    Jim Ley
    Feb 5, 2004
  5. VK
    Replies:
    4
    Views:
    356
    Thomas 'PointedEars' Lahn
    Jan 12, 2006
Loading...

Share This Page