Strange problems with JSON and Safari

Discussion in 'Javascript' started by Nick, Mar 30, 2008.

  1. Nick

    Nick Guest

    I'm trying to develop an AJAX application for the iphone which uses
    JSON (as it's smaller than passing around HTML or XML).

    Problem is Safari's not playing nice with JSON.

    I have this response from my script:

    ["Value 1","Value 2","Value 3","Value 4","Value 5"]

    I've tried a couple of ways of parsing this into javascript values:

    status = new Function("return "+xmlHttp.responseText)();

    Which works fine in firefox and IE, this gives me an array. In safari
    it returns a string, this means when I do status.length I get a count
    of all the characters in the string.

    I've even tried the YUI JSON library but I get the same result.

    Has anyone been able to use JSON arrays in Safari?
    Nick, Mar 30, 2008
    #1
    1. Advertising

  2. Nick

    Ed Guest

    On Mar 30, 5:36 pm, Nick <> wrote:
    > status = new Function("return "+xmlHttp.responseText)();
    >
    > Which works fine in firefox and IE, this gives me an array. In safari
    > it returns a string, this means when I do status.length I get a count
    > of all the characters in the string.
    >
    > I've even tried the YUI JSON library but I get the same result.


    You are probably assigning to the window.status property:

    http://developer.mozilla.org/en/docs/DOM:window.status
    Ed, Mar 31, 2008
    #2
    1. Advertising

  3. Nick

    Nick Guest

    On Mar 31, 1:45 pm, Ed <> wrote:
    > On Mar 30, 5:36 pm, Nick <> wrote:
    >
    > > status = new Function("return "+xmlHttp.responseText)();

    >
    > > Which works fine in firefox and IE, this gives me an array. In safari
    > > it returns a string, this means when I do status.length I get a count
    > > of all the characters in the string.

    >
    > > I've even tried the YUI JSON library but I get the same result.

    >
    > You are probably assigning to the window.status property:
    >
    > http://developer.mozilla.org/en/docs/DOM:window.status


    Thanks, I changed the name of the status var and it seems to be
    working now :)
    Nick, Mar 31, 2008
    #3
  4. Nick wrote:
    > On Mar 31, 1:45 pm, Ed <> wrote:
    >> On Mar 30, 5:36 pm, Nick <> wrote:
    >>> status = new Function("return "+xmlHttp.responseText)();
    >>> Which works fine in firefox and IE, this gives me an array. In safari
    >>> it returns a string, this means when I do status.length I get a count
    >>> of all the characters in the string.
    >>> I've even tried the YUI JSON library but I get the same result.

    >> You are probably assigning to the window.status property:
    >>
    >> http://developer.mozilla.org/en/docs/DOM:window.status

    >
    > Thanks, I changed the name of the status var and it seems to be
    > working now :)


    Simply declaring your identifier as a variable would have resolved your
    problem once and for all:

    var status = ...;

    Without a declaration, `status' (or any other identifier) in an assignment
    expression is _not_ a variable (a property of the Variable Object of the
    execution context that has the DontDelete attribute) but a reference to a
    property of an (at that point unknown) object in the Scope Chain, here a
    Window object that can be referred to by the `window' property.

    Suppose you have changed the identifier now, it still can happen *NOW* that
    in another execution environment (say, another browser) an object in the
    Scope Chain of the execution context has a property that you involuntarily
    refer to by it which can cause you and your users any kind of trouble (from
    nothing to an unchanged value of the ReadOnly property to a user-annoying
    runtime error because the property owner is a host object -- all of which
    has been observed already).

    On the other hand, the variable declaration is safe as it limits the scope
    of the identifier to the current execution context and prevents further
    following of the identifier resolution algorithm along the Scope Chain (the
    Variable Object comes before all other objects in the Scope Chain, except
    one uses a `with' statement).


    PointedEars
    --
    Use any version of Microsoft Frontpage to create your site.
    (This won't prevent people from viewing your source, but no one
    will want to steal it.)
    -- from <http://www.vortex-webdesign.com/help/hidesource.htm>
    Thomas 'PointedEars' Lahn, Mar 31, 2008
    #4
    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. Florian Frank
    Replies:
    0
    Views:
    226
    Florian Frank
    Jun 30, 2009
  2. sajuptpm
    Replies:
    2
    Views:
    315
    sajuptpm
    Dec 28, 2012
  3. Acácio Centeno
    Replies:
    1
    Views:
    240
    dieter
    Feb 15, 2013
  4. Bryan Britten
    Replies:
    9
    Views:
    255
    Bryan Britten
    May 28, 2013
  5. David Karr
    Replies:
    1
    Views:
    152
    David Karr
    Jun 17, 2013
Loading...

Share This Page