JSFiddle - React, Tailwind, and code Playground
HTML
<dic id='click'>Нижми сюда</div>
JavaScript
function json(data){
var jobject = JSON.parse(data, function (key, value) {
var type;
if (value && typeof value === 'object') {
type = value.type;
if (typeof type === 'string' && typeof window[type] === 'function') {
return new (window[type])(value);
}
}
return value;
});
if ( jobject ) return jobject;
else return false;
}
$('#click').click(function(){
var res = json('{"result":"получилось"}');
alert(res.result);
});