From: Douglas Crockford <douglas@crockford.com>
Date: Tue, Mar 6, 2007 at 9:30 AM
Subject: Re: Minor fix in json.js
To: Prathapnirmal <prathapnirmal@gmail.com>
Thanks.
Prathapnirmal wrote:
Hi Douglas,
First of all thanks for the awsome JSON. Even a subset of javascript does excellent job.I am using json.js in one of my projects and came across a minor bug which requires a fix. It's in the filter walker function,if (typeof filter === 'function') {
function walk(k, v) {
if (v && typeof v === 'object') {
for (var i in v) {if (v.hasOwnProperty(i)) {
v[i] = walk(i, v[i]);
}
}
}return filter(k, v);
}j = walk('', j);
}
return j;The final result of the walker should be the return value, else the following example fails,
var filter = function(k, v) {
switch(v.type) {
case type1:
return type1();
case type2
....
}
}
var json_data = {type: "type1", collection: [{type: "type2", ...}]};
var type1_obj = json_data.parseJSON(filter);
In the above example I will be expecting a type1 object whereas what will I actually get is a simple object. The actual reason is that the final object that is created in the filter function is lost.Again thanks for such a good alternative to xml. Please let me know on what should I do to do this fix so that it becomes useful to everyone and not everyone spends time on debugging the same issue.
thanks
~
Prathap
No comments:
Post a Comment