Strange problems with JSON and Safari

N

Nick

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?
 
T

Thomas 'PointedEars' Lahn

Nick said:
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
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top