G
G
Grigory Dikiy2016-01-27 20:51:29
JavaScript
Grigory Dikiy, 2016-01-27 20:51:29

How to get an object from JSON?

Good day. The task is to get an object from an external JSON file and save it to a variable:

var App = {
  blockElem: undefined,
  elem: undefined,
  data: undefined,
  init: function(str){
    this.blockElem = str;
    this.elem = document.getElementById(this.blockElem);
    this.getData();
    this.renderDefault();
    this.logInfo();
  },
  renderDefault: function(){
    this.elem.innerHTML = this.blockElem;
  },
  renderHead: function(){

  },
  getData: function(){
    this.data = $.getJSON('data.json');
  },
  logInfo: function(){
    console.log(this.data);
  },
}

This code does not return a pure object.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2016-01-27
@DP-Studio

jQuery.parseJSON( '{ "name": "John" }' );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question