Skip to Content | Skip to Navigation


dojo.fromJson

Status:Draft
Version:1.0
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

See also

  • dojo.toJson
  • dojo.queryToObject