This project is archived and is in readonly mode.

#1165 ✓wontfix
Aicke Schulz

Solution for JSON.from

Reported by Aicke Schulz | February 3rd, 2011 @ 04:07 PM

After I used the following as an standalone function for a while, I've seen the new .from() functions in MooTools 1.3, so I've changed it into a JSON method. It works, is html4/5 compliant and cross browser compatible within 3 lines of code. Hope you like it.


JSON.from = function(element){
    var dataString = String(element.getProperty('class')); // String casting needed for IE
    var jsonString = dataString.substring(dataString.indexOf("{"), dataString.lastIndexOf("}")+1); // get json data
    return $merge({}, JSON.decode(jsonString)); // with $merge the json cannot be undefined
};

Maybe someone wants to extends it for the "text" property and retrieve(). I've never needed that because I wanted an "invisible" solution where the data is already in the html source.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

People watching this ticket

Pages