I'd like to extract some values from Json format:
The file contain this values
{"latitude":45.89,"longitude":12.3,"timezone":"Europe/Rome","currently":{"time":1542528923,"summary":"Clear","icon":"clear-day","precipIntensity":0,"precipProbability":0,"temperature":5.34,"apparentTemperature":5.34,"dewPoint":-1.62,"humidity":0.61,"pressure":1023.79,"windSpeed":0.98,"windGust":2.25,"windBearing":24,"cloudCover":0,"uvIndex":0,"visibility":13.76,"ozone":332.58},"offset":1}
I d like to extract temperate humidity.. Etc
Extract values from json format
Moderator: Martin
Re: Extract values from json format
Use fromJSON() to convert the json.
{js} is now a nested map-list object. Access temperature by
To access humidity,
Add condition debug dialog after the script to check the value of js and use the one you need.
You posted a related question about using location variable in HTTP request. There is a similar question already before and cover both (location and json). There is also example flow you can modify to suit your need : viewtopic.php?f=5&t=7457
Code: Select all
res = '{"latitude":45.89,"longitude":12.3,"timezone":"Europe/Rome","currently":{"time":1542528923,"summary":"Clear","icon":"clear-day","precipIntensity":0,"precipProbability":0,"temperature":5.34,"apparentTemperature":5.34,"dewPoint":-1.62,"humidity":0.61,"pressure":1023.79,"windSpeed":0.98,"windGust":2.25,"windBearing":24,"cloudCover":0,"uvIndex":0,"visibility":13.76,"ozone":332.58},"offset":1}';
js = fromJSON(res);
Code: Select all
temp = js["currently"]["temperature"]; // 5.34
Code: Select all
temp = js["currently"]["humidity"]; // 0.61
You posted a related question about using location variable in HTTP request. There is a similar question already before and cover both (location and json). There is also example flow you can modify to suit your need : viewtopic.php?f=5&t=7457
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Re: Extract values from json format
Thank you very much.. now another question:
from same list i'd like to access the list ot temperatures of the day
{"latitude":45.89,"longitude":12.3,"timezone":"Europe/Rome","currently":
{"time":1542957662,...,"temperature":6.91,...},
"hourly":{"summary":"Rain starting this evening.","icon":"rain","data":[
{"time":1542956400,...,"temperature":6.68,"apparentTemperatu....1},
{"time":1542960000,...,"temperature":7.34,"apparentTemperature":7.34,..},
{"time":1542963600,...,"temperature":8.08,"
I'd like to make a window dialog with temperatures : [ 7, 7, 8 ]
from same list i'd like to access the list ot temperatures of the day
{"latitude":45.89,"longitude":12.3,"timezone":"Europe/Rome","currently":
{"time":1542957662,...,"temperature":6.91,...},
"hourly":{"summary":"Rain starting this evening.","icon":"rain","data":[
{"time":1542956400,...,"temperature":6.68,"apparentTemperatu....1},
{"time":1542960000,...,"temperature":7.34,"apparentTemperature":7.34,..},
{"time":1542963600,...,"temperature":8.08,"
I'd like to make a window dialog with temperatures : [ 7, 7, 8 ]
Re: Extract values from json format
SOLUTION:
js = fromJSON(weatherDark);
RainDa1 = js["currently"]["precipProbability"];
RainDa="{RainDa1*100,numberformat,0}";
TempDa1 = js["currently"] ["temperature"] ;
TempDa ="{TempDa1,numberformat,0}";
HuDa1 = js["currently"] ["humidity"]; // 0.61
HuDa ="{HuDa1*100,numberformat,0}";
StatusDa = js["currently"] ["summary"];
HourlyDa = js["hourly"] ["summary"];
//Array temp e precip [mm] giornaliere
DataArr = js["hourly"]["data"];
TemG=newList() ;
PrecG=newList() ;
TempL=newList();
TempL= [1 to 36];
a=1;
for(i in TempL)
{
TempI=(DataArr["temperature"]);
PrecIn=(DataArr["precipIntensity"]);
TempIc ="{TempI,numberformat,0}";
PrecInc="{PrecIn,numberformat,0}";
if ((i==a))
{
addElement(TemG,TempIc);
addElement(PrecG,PrecInc);
a=a+4;
}
}
js = fromJSON(weatherDark);
RainDa1 = js["currently"]["precipProbability"];
RainDa="{RainDa1*100,numberformat,0}";
TempDa1 = js["currently"] ["temperature"] ;
TempDa ="{TempDa1,numberformat,0}";
HuDa1 = js["currently"] ["humidity"]; // 0.61
HuDa ="{HuDa1*100,numberformat,0}";
StatusDa = js["currently"] ["summary"];
HourlyDa = js["hourly"] ["summary"];
//Array temp e precip [mm] giornaliere
DataArr = js["hourly"]["data"];
TemG=newList() ;
PrecG=newList() ;
TempL=newList();
TempL= [1 to 36];
a=1;
for(i in TempL)
{
TempI=(DataArr["temperature"]);
PrecIn=(DataArr["precipIntensity"]);
TempIc ="{TempI,numberformat,0}";
PrecInc="{PrecIn,numberformat,0}";
if ((i==a))
{
addElement(TemG,TempIc);
addElement(PrecG,PrecInc);
a=a+4;
}
}