dojo.fromJson

Available:since v0.9

Parses a JSON string to return a JavaScript object.

Introduction

This function creates a JavaScript object from a passed JSON string, such as one created by dojo.toJson or the response data from an Ajax call with handleAs:"json" enabled.

1
2
3
4
5
6
7
dojo.xhrGet({
  url:"foo.php", handleAs:"json",
  load: function(data){
      // data is a JavaScript object. The content of foo.php
      // was passed through dojo.fromJson
  }
});

Usage

1
2
3
4
var json = '{"a":"one","b":3,"c":true}';
var obj = dojo.fromJson(json);
console.log(obj.a, obj.b, obj.c);
>>> one 3 true
Error in the documentation? Can’t find what you are looking for? Let us know!