E
E
EEM2020-08-05 20:52:24
React
EEM, 2020-08-05 20:52:24

How to render JSON object received via API?

Friends, tell me. There is such a JSON object received from the server. I need to output by key, for example {s1_h1_text}. What is the best way to do this?

{
  "text": {
      "s1_h1_text": {
          "id": 1,
          "text": "заголовок 1-го уровня",
          "lang_id": 1
      },
      "s1_h2_text": {
          "id": 2,
          "text": "заголовок 2-го уровня",
          "lang_id": 1
      },
      "s1_h3_text": {
          "id": 3,
          "text": "заголовок 3-го уровня",
          "lang_id": 1
      }
  }
}

Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Timur Kostenko, 2020-08-06
@eem-kz

So bring it out
const {s1_h1_text, s1_h2_text, s1_h3_text} = text;

F
feniksdv, 2020-08-05
@feniksdv

How are you going to get it by reference? Those. the application knocked on the link and received json?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question