Skip to content

Commit 5394740

Browse files
committed
Fixed a problem in how it was representing arrays and undefined values.
1 parent d7d753f commit 5394740

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

jquery.json.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
{
8181
var ret = [];
8282
for (var i = 0; i < o.length; i++)
83-
ret.push( $.toJSON(o[i]) );
83+
ret.push( $.toJSON(o[i]) || "null" );
8484

8585
return "[" + ret.join(",") + "]";
8686
}

jquery.json.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ function _test(o, correct)
3030

3131
// 'console' comes from FireBug
3232
function testJSON(o, expected) {
33-
_test(o, expected);
3433
try { _test(o, expected); }
3534
catch (e) { console.error("Conversion Error:", e.message) }
3635

@@ -56,6 +55,13 @@ testJSON([2, 5], "[2,5]");
5655
testJSON(function() {}, undefined);
5756
testJSON(function() {}, undefined);
5857
testJSON(null, "null");
58+
testJSON(["C:\\A.TXT","C:\\B.TXT","C:\\C.TXT","C:\\D.TXT"], '["C:\\\\A.TXT","C:\\\\B.TXT","C:\\\\C.TXT","C:\\\\D.TXT"]');
59+
testJSON({"dDefault": "1.84467440737E+19"}, '{"dDefault":"1.84467440737E+19"}');
60+
testJSON([undefined, undefined, 1, 2], '[null,null,1,2]');
61+
testJSON([0, false, function() {}], '[0,false,null]');
62+
testJSON(0, '0');
63+
testJSON(false, 'false');
64+
testJSON(null, 'null');
5965
testJSON(new Date(2008, 9, 25), '"2008-10-25T05:00:00.000Z"');
6066

6167
// Temporarily remove Date's toJSON and JSON.stringify

0 commit comments

Comments
 (0)