JavaScript DHTML/Dojo toolkit/JSON
Convert array to JSON
<html>
<head>
<link rel="StyleSheet" type="text/css"
href="js/dojo/dijit/themes/tundra/tundra.css">
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/",
parseOnLoad : true
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script>
function Foo( ) {
var o = {a:1, b:2, c:3, d:4};
alert( dojo.toJson(o, true));
}
</script>
</head>
<body class="tundra" onload=Foo()>
</body>
</html>
Convert object to JSON
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/"
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script>
function doCoords() {
alert(dojo.toJson(dojo.coords("myDiv")));
}
</script>
</head>
<body onLoad="doCoords();">
<div id="myDiv">I am myDiv</div>
</body>
</html>
Convert query string to JSON
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/"
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script language="JavaScript" type="text/javascript">
var s = dojo.objectToQuery({
c1 : "A",
c2 : "B",
c3 : "C"
});
alert(dojo.toJson(dojo.queryToObject(s)));
</script>
</head>
<body></body>
</html>