필터 지우기
필터 지우기

How to parse webpage JSON with temperatures in it.

조회 수: 2 (최근 30일)
Mantas Dabrovolskas
Mantas Dabrovolskas 2023년 6월 21일
댓글: Jon 2023년 6월 21일
I am making a simple temperature graph with Thingspeak. I want to use my cities publicly available meteorology API - https://api.meteo.lt/v1/stations/vilniaus-ams/observations/2023-06-21
How would I read the temperature data and put it onto graph (merge it with inside temperature)?
Here is how I do it with my inside temperature sensor (I used standard Matlab example and edited it - added three hours to fix my time zone):
[dustData,Timestamps]=thingSpeakRead(XXXXXXX,'Fields',1,'NumPoints',100);
plot(Timestamps+hours(3),dustData,'red');
ylabel('Degrees');
title('Temperature');
grid on;

채택된 답변

Jon
Jon 2023년 6월 21일
You can use webread
data = webread('https://api.meteo.lt/v1/stations/vilniaus-ams/observations/2023-06-21')
data = struct with fields:
station: [1×1 struct] observations: [12×1 struct]
  댓글 수: 1
Jon
Jon 2023년 6월 21일
편집: Jon 2023년 6월 21일
In the above example, the air temperatures (I think that is what you want) are in data.observations.airTemperature

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Lakshay Rose
Lakshay Rose 2023년 6월 21일
Hi Mantas Dabrovolskas,
As per my understanding you are trying to read the JSON data returned from the API call from the mentioned URL.
You can follow the below steps to achieve the desired result –
  1. Retrieve the data from the API using the “webread” function in MATLAB. The API returns data in JSON format, so you'll need to parse it to extract the temperature values.
  2. Retrieve the inside temperature data from “ThingSpeak” using the “thingSpeakRead” function, similar to what you already have in your code.
  3. Merge both the dataset and plot the graph.
You can also refer to the documentation of “webread” for further information –
  댓글 수: 1
Jon
Jon 2023년 6월 21일
From my simple example above, it seems that webread already parses the contents and returns it in a structure, so it is not necessary to use jsondecode

댓글을 달려면 로그인하십시오.

커뮤니티

더 많은 답변 보기:  ThingSpeak 커뮤니티

카테고리

Help CenterFile Exchange에서 Web Services에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by