V
V
Vadim Somov2018-08-13 14:41:14
JavaScript
Vadim Somov, 2018-08-13 14:41:14

How to parse data from json?

Hello. I have a db in firebase , here it is - 5b716cd2b84f3528706522.png.
and my get request is

function json(response) {
  return response.json();
}
function saveData(response) {
  const data = response;
  console.log(data); 
}

fetch(`${fireURL}/.json`, {
  method: 'GET',
})
  .then(json)
  .then(saveData);

This came to the console - 5b716e14262ea113843142.png
How to parse this data and, for example, use it in the DOM?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
alexalexes, 2018-08-13
@alexalexes

Relevant function:
https://developer.mozilla.org/ru/docs/Web/JavaScri...

V
Vlad, 2018-08-13
@DaFive

This is the received json, in the form of a JS object.
Run through the object and get the data you need:

function saveData(response) {
  const data = response;
  console.log(data); 

  for( var prop in data) {
    console.log(data[prop], data[prop]['descrName']); //и т.д.
  }
}

A
Azilla, 2018-08-14
@nonamemovich

if you need to convert a string to json, then use json.parse

var jsonData = {};
try {
  jsonData = JSON.parse(inputStr);
} catch (e) {
  // обработать ошибку парсинга
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question