Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Strange problems with JSON and Safari

Reply
Thread Tools

Strange problems with JSON and Safari

 
 
Nick
Guest
Posts: n/a
 
      03-30-2008
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?
 
Reply With Quote
 
 
 
 
Ed
Guest
Posts: n/a
 
      03-31-2008
On Mar 30, 5:36*pm, Nick <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Nick
Guest
Posts: n/a
 
      03-31-2008
On Mar 31, 1:45 pm, Ed <(E-Mail Removed)> wrote:
> On Mar 30, 5:36 pm, Nick <(E-Mail Removed)> 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
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      03-31-2008
Nick wrote:
> On Mar 31, 1:45 pm, Ed <(E-Mail Removed)> wrote:
>> On Mar 30, 5:36 pm, Nick <(E-Mail Removed)> 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>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lib to generate XML/JSON[P] output from a DTD/XSD/JSON Schema/etc Acácio Centeno Python 1 02-15-2013 07:34 AM
I am facing an issue while decoding json string using json.loads sajuptpm Python 2 12-28-2012 07:16 AM
[ANN] Security Fix json-1.1.7 for json_pure and json gems Florian Frank Ruby 0 06-30-2009 05:18 PM
"JSON for ASP" at json.org Tuğrul Topuz ASP General 1 06-27-2008 11:37 PM
strange result with json-server & zope astarocean Python 3 09-18-2006 02:59 AM



Advertisments