On Feb 12, 2011, at 12:25 PM, Garret Wilson wrote:
> I'm happy to see that MooTools has JSON processing support---now I
> won't have to maintain my own version which I created five years ago.
> I was also excited to discover (I've been away from web programming
> for a while) that many browsers nowadays provide native JSON
> capabilities:
>
> http://stackoverflow.com/questions/891299/browser-native-json-support-window-json
>
> I assumed that the MooTools JSON version would delegate to the native
> browser version if present. I looked at the code; apparently MooTools
> at least checks to see if the browser already has a JSON object, but
> then it goes and adds its own encode() and decode() methods() without
> delegating to the native parse()/stringify()/whatever() methods of the
> browser.
>
> That's disappointing. Am I missing something, or does MooTools lack
> JQuery's ability to use the browser's native JSON processing
> capabilities if present?
I agree that MT should probably handle it for you, but the beauty is that you
can implement it yourself. Maybe something like......
if (this.JSON) {
Object.append(JSON, {
encode: function (obj) {
return this.JSON.stringify(obj);
},
decode: function (string, secure) {
return this.JSON.parse(string);
}
});
}
I've not done any testing, but seems like something similar should work. Happy
coding.
~Philip
http://lonestarlightandsound.com/