469,906 Members | 2,180 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,906 developers. It's quick & easy.

JavaScript JSON stringifier

Hi,

Does anyone have a freely available JavaScript JSON stringifier. So far
my search has been in vain, the one offered on
http://www.json.org/json.js does not seem to work for me.

Nov 30 '06 #1
5 3985
I looked into the original problem and noticed the following:

As soon as I extend the Object.prototype with another function
(toJSONString in this case), my Ajax.Request fails in Firefox only.

Example:

Object.prototype.toJSONString = function() {
return true;
}
new Ajax.Request(
"http://www.example.com",
{
onComplete: function() {
alert('complete')
}
}
);

On Internet Explorer this works, but on Firefox this will fail, and I
don't get the 'complete' alert. Any ideas on the reason and how to
solve this?

Gerry Vandermaesen wrote:
Hi,

Does anyone have a freely available JavaScript JSON stringifier. So far
my search has been in vain, the one offered on
http://www.json.org/json.js does not seem to work for me.
Nov 30 '06 #2
Gerry Vandermaesen wrote:
I looked into the original problem and noticed the following:

As soon as I extend the Object.prototype with another function
(toJSONString in this case), my Ajax.Request fails in Firefox only.

Example:

Object.prototype.toJSONString = function() {
return true;
}
new Ajax.Request(
"http://www.example.com",
{
onComplete: function() {
alert('complete')
}
}
);

On Internet Explorer this works, but on Firefox this will fail, and I
don't get the 'complete' alert. Any ideas on the reason and how to
solve this?
This is - Ajax.Request - from Prototype.js? As Prototype.js is not
ECMAScript compatible (relies entirely on implementation decisions not
to throw exceptions where exceptions may be thrown) it is not likely to
behave consistently across ECMA 262, 3rd Ed. implementations. Seeing
that happen is not unexpected.

If you want an analysis of the cause and effect relationships that are
happening here you will need to provide a minimal text-case that
demonstrates the issue (in isolation from everything that is
irrelevant) rather than a non-testable fragment code.

Richard.

Nov 30 '06 #3
Yes, I do use an unmodified prototype.js for the AJAX request.

I set up an example at http://www.allyourbase.be/test/index.html

The example will act as expected under IE7, but does not throw the
alert under Firefox (using 2.0).

Richard Cornford wrote:
Gerry Vandermaesen wrote:
I looked into the original problem and noticed the following:

As soon as I extend the Object.prototype with another function
(toJSONString in this case), my Ajax.Request fails in Firefox only.

Example:

Object.prototype.toJSONString = function() {
return true;
}
new Ajax.Request(
"http://www.example.com",
{
onComplete: function() {
alert('complete')
}
}
);

On Internet Explorer this works, but on Firefox this will fail, and I
don't get the 'complete' alert. Any ideas on the reason and how to
solve this?

This is - Ajax.Request - from Prototype.js? As Prototype.js is not
ECMAScript compatible (relies entirely on implementation decisions not
to throw exceptions where exceptions may be thrown) it is not likely to
behave consistently across ECMA 262, 3rd Ed. implementations. Seeing
that happen is not unexpected.

If you want an analysis of the cause and effect relationships that are
happening here you will need to provide a minimal text-case that
demonstrates the issue (in isolation from everything that is
irrelevant) rather than a non-testable fragment code.

Richard.
Nov 30 '06 #4
I also noted this problem only occurs with prototype version 1.5.0_rc1,
which is shipped with and required by the script.aculo.us libraries.
When using prototype 1.4.0 I didn't have a problem. However, we do make
use of the script.aculo.us libraries too on our site.

Gerry Vandermaesen wrote:
Yes, I do use an unmodified prototype.js for the AJAX request.

I set up an example at http://www.allyourbase.be/test/index.html

The example will act as expected under IE7, but does not throw the
alert under Firefox (using 2.0).

Richard Cornford wrote:
Gerry Vandermaesen wrote:
I looked into the original problem and noticed the following:
>
As soon as I extend the Object.prototype with another function
(toJSONString in this case), my Ajax.Request fails in Firefox only.
>
Example:
>
Object.prototype.toJSONString = function() {
return true;
}
new Ajax.Request(
"http://www.example.com",
{
onComplete: function() {
alert('complete')
}
}
);
>
On Internet Explorer this works, but on Firefox this will fail, and I
don't get the 'complete' alert. Any ideas on the reason and how to
solve this?
This is - Ajax.Request - from Prototype.js? As Prototype.js is not
ECMAScript compatible (relies entirely on implementation decisions not
to throw exceptions where exceptions may be thrown) it is not likely to
behave consistently across ECMA 262, 3rd Ed. implementations. Seeing
that happen is not unexpected.

If you want an analysis of the cause and effect relationships that are
happening here you will need to provide a minimal text-case that
demonstrates the issue (in isolation from everything that is
irrelevant) rather than a non-testable fragment code.

Richard.
Nov 30 '06 #5

Gerry Vandermaesen wrote:
I also noted this problem only occurs with prototype version 1.5.0_rc1,
which is shipped with and required by the script.aculo.us libraries.
When using prototype 1.4.0 I didn't have a problem. However, we do make
use of the script.aculo.us libraries too on our site.
Then you will have to deal with that. An old version of json.js used a
JSON object with two methods rather than extending built-in objects,
search for "JSON serialization" at:

news:rubyonrails-spinoffs

<URL: http://groups.google.com.au/group/rubyonrails-spinoffs >
--
Fred

Nov 30 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by G Matthew J | last post: by
2 posts views Thread by paulfe4 | last post: by
2 posts views Thread by Kevin Newman | last post: by
10 posts views Thread by Frank Millman | last post: by
1 post views Thread by Weston | last post: by
23 posts views Thread by dhtmlkitchen | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.