By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,512 Members | 1,179 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,512 IT Pros & Developers. It's quick & easy.

JavaScript JSON stringifier

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

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.