views:

604

answers:

2

Hello everybody,

why does the JSON.stringify-Function converts a string.Empty ("") to a "null"-String? The problem, why i'm not using:

JSON.parse(json, function(key, value) { if (typeof value === 'string') { if (value == 'null') return ''; return value; } });

...is, if somebody really write "null" (is very unlikely, but possible), i have a problem to...

thank for each answer!

A: 

now i note, the problem is, if you're using like this: JSON.stringify({a:document.getElementById('id').value}); -> {"a":"null"}

yes, this works in Internet Explorer to: JSON.stringify({a:''}); -> {"a":""}

but i haven't found a solution for that problem yet.... if somebody have an idea, i would be very happy.

Beni
A: 

hello again,

now the esiest solution for this problem is, to pack the "document.getElementById('id').value" expression in the constructor of the String class:

JSON.stringify({a:new String(document.getElementById('id').value)}); -> {"a":""}

i can't find the primary problem, but with this, it's working well in Internet Explorer as well in FireFox.

i'm not very happy with this dirty solution, but the effort is not to much.

JSON library: http://www.json.org/json2.js

Beni