Permalink
Browse files

Support Hash in JSON

  • Loading branch information...
1 parent 42467d0 commit 2433c48adfb9768a9b33a45f4f937af697703396 @arian arian committed Feb 12, 2011
Showing with 4 additions and 4 deletions.
  1. +4 −4 Source/Utilities/JSON.js
@@ -51,12 +51,12 @@ JSON.encode = JSON.stringify || function(obj){
return '"' + obj.replace(/[\x00-\x1f\\"]/g, escape) + '"';
case 'array':
return '[' + obj.map(JSON.encode).clean() + ']';
- case 'object':
+ case 'object': case 'hash':
var string = [];
- for (var key in obj){
- var json = JSON.encode(obj[key]);
+ Object.each(obj, function(value, key){
+ var json = JSON.encode(value);
if (json) string.push(JSON.encode(key) + ':' + json);
- }
+ });
return '{' + string + '}';
case 'number': case 'boolean': return '' + obj;
case 'null': return 'null';

0 comments on commit 2433c48

Please sign in to comment.