Check documentation for the latest version of dhtmlxSuite s2j DHTMLX Docs

s2j

converts string into JSON format

string s2j(string str);
strstringstring to convert
stringstring in JSON format

Example

var t = window.dhx.s2j('{my_key: "my_value"}'); console.log(t.my_key); // my_value

Details

It can be used for parsing server responses:

<?php // server side if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "aboutMe") { print_r('{name: "James", age: 26, role: "Site Admin"}'); } ?>


// client side window.dhx.ajax.get("server.php?action=aboutMe", function(r){ var t = window.dhx.s2j(r.xmlDoc.responseText); if (t != null) { for (var a in t) console.log(a+": "+t[a]); } else { dhtmlx.message({type: "error", text: "...."}); } });

the result will be:
name: James
age: 26
role: Site Admin

Back to top