J
J
JuliaLy2022-01-30 16:39:01
JavaScript
JuliaLy, 2022-01-30 16:39:01

How to extract values ​​of individual array/JSON fields?

Greetings.
There is JSON (or an array with JSON elements, correct as correct) which I receive via API in response.
Here is a snippet of the data structure:

{"lat":59.57,"lon":30.19,"timezone":"Europe/Moscow","timezone_offset":10800,"current":{"dt":1643461224,"sunrise":1643437084,"sunset":1643465183,"temp":-3.38,"feels_like":-7.07,"pressure":1005,"humidity":94,"dew_point":-4.11,"uvi":0,"clouds":100,"visibility":10000,"wind_speed":2.54,"wind_deg":187,"wind_gust":6.33,"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}]},"daily":


in a readable form like this:
61f692db9f48b530011944.png

Full answer at this link .

I extract the values ​​of the first fields (up to current) through a dot without problems (example):
var lat = request.response.lat;
then I display lat, I get 59.57 - expectations = fact The

question is, how can I extract fields deeper in the array?
(for example, moonrise or day)
I understand that the cycle will probably save, but the syntax is not mine - I'm swimming.
can you tell me something cleaner, I will be grateful for any tips and code examples!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Kadyrov, 2022-01-31
@Ahmad66617

You can extract them without enumeration - by index - for example -> request.response.daily[0].moonrise and if the indexes come randomly - then filter js will save you - and there is a condition in the filter, for example, the presence of a field in the object.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question