1
I have the following Json:
{
"cod": "200",
"message": 0.0055,
"cnt": 40,
"list": [
{
"dt": 1560319200,
"main": {
"temp": 15.15,
"temp_min": 14.49,
"temp_max": 15.15,
"pressure": 1021.11,
"sea_level": 1021.11,
"grnd_level": 995.76,
"humidity": 96,
"temp_kf": 0.66
},
"weather": [
{
"id": 801,
"main": "Clouds",
"description": "céu pouco nublado",
"icon": "02n"
}
],
"clouds": {
"all": 19
},
"wind": {
"speed": 0.78,
"deg": 246.743
},
"sys": {
"pod": "n"
},
"dt_txt": "2019-06-12 06:00:00"
},
{
"dt": 1560330000,
"main": {
"temp": 14.69,
"temp_min": 14.19,
"temp_max": 14.69,
"pressure": 1020.69,
"sea_level": 1020.69,
"grnd_level": 995.4,
"humidity": 95,
"temp_kf": 0.5
},
"weather": [
{
"id": 801,
"main": "Clouds",
"description": "céu pouco nublado",
"icon": "02n"
}
],
"clouds": {
"all": 17
},
"wind": {
"speed": 0.7,
"deg": 256.122
},
"sys": {
"pod": "n"
},
"dt_txt": "2019-06-12 09:00:00"
},
{
"dt": 1560340800,
"main": {
"temp": 19.68,
"temp_min": 19.35,
"temp_max": 19.68,
"pressure": 1021.93,
"sea_level": 1021.93,
"grnd_level": 996.86,
"humidity": 74,
"temp_kf": 0.33
},
"weather": [
{
"id": 801,
"main": "Clouds",
"description": "céu pouco nublado",
"icon": "02d"
}
],
"clouds": {
"all": 23
},
"wind": {
"speed": 0.26,
"deg": 210.741
},
"sys": {
"pod": "d"
},
"dt_txt": "2019-06-12 12:00:00"
},
{
"dt": 1560351600,
"main": {
"temp": 25.72,
"temp_min": 25.55,
"temp_max": 25.72,
"pressure": 1020.78,
"sea_level": 1020.78,
"grnd_level": 995.84,
"humidity": 55,
"temp_kf": 0.17
},
"weather": [
{
"id": 802,
"main": "Clouds",
"description": "nuvens dispersas",
"icon": "03d"
}
],
"clouds": {
"all": 36
},
"wind": {
"speed": 1.34,
"deg": 72.064
},
"sys": {
"pod": "d"
},
"dt_txt": "2019-06-12 15:00:00"
},
{
"dt": 1560362400,
"main": {
"temp": 25.68,
"temp_min": 25.68,
"temp_max": 25.68,
"pressure": 1018.44,
"sea_level": 1018.44,
"grnd_level": 993.46,
"humidity": 59,
"temp_kf": 0
},
"weather": [
{
"id": 802,
"main": "Clouds",
"description": "nuvens dispersas",
"icon": "03d"
}
],
"clouds": {
"all": 47
},
"wind": {
"speed": 2.12,
"deg": 81.239
},
"sys": {
"pod": "d"
},
"dt_txt": "2019-06-12 18:00:00"
},
{
"dt": 1560373200,
"main": {
"temp": 18.45,
"temp_min": 18.45,
"temp_max": 18.45,
"pressure": 1019.96,
"sea_level": 1019.96,
"grnd_level": 994.89,
"humidity": 97,
"temp_kf": 0
},
"weather": [
{
"id": 802,
"main": "Clouds",
"description": "nuvens dispersas",
"icon": "03n"
}
],
"clouds": {
"all": 25
},
"wind": {
"speed": 0.93,
"deg": 76.605
},
"sys": {
"pod": "n"
},
"dt_txt": "2019-06-12 21:00:00"
},
{
"dt": 1560384000,
"main": {
"temp": 17.25,
"temp_min": 17.25,
"temp_max": 17.25,
"pressure": 1021.66,
"sea_level": 1021.66,
"grnd_level": 996.24,
"humidity": 97,
"temp_kf": 0
},
"weather": [
{
"id": 803,
"main": "Clouds",
"description": "nuvens quebradas",
"icon": "04n"
}
],
"clouds": {
"all": 59
},
"wind": {
"speed": 0.68,
"deg": 309.784
},
"sys": {
"pod": "n"
},
"dt_txt": "2019-06-13 00:00:00"
}
],
"city": {
"id": 3459712,
"name": "Joinville",
"coord": {
"lat": -26.3045,
"lon": -48.8487
},
"country": "BR",
"population": 461304,
"timezone": -10800
}
}
I wonder how I can generate a new Json, through the above described with only the highest temperature and lowest temperature of the day, and not every 3 hours the way Json returns me today.
Ex: For the day 2019-06-12
The largest temp_max
was: 25.72, and the smallest temp_min
was: 14:19.
I would like to generate a new Json +- like this :
{
"list":[
{
"dia":"2019-06-12",
"temp_min":14.19,
"temp_max":2572
}]
}
I’ve already separated Json into objects like below, I just don’t know how to do to check objects with the same date, to get the highest and lowest values.
here I create my object:
namespace HBSIS.Models.WeatherViewModels
{
public class RootObjectWeather
{
public Response[] list { get; set; }
}
public class Response
{
public string dt_txt { get; set; }
public Main main { get; set; }
public List<Weather> weather { get; set; }
}
public class Main
{
[JsonProperty("temp")]
public string Temperature { get; set; }
[JsonProperty("temp_min")]
public string MinimumTemperature { get; set; }
[JsonProperty("temp_max")]
public string MaximumTemperature { get; set; }
[JsonProperty("humidity")]
public string Humidity { get; set; }
}
public class Weather
{
[JsonProperty("description")]
public string Description { get; set; }
}
}
var result = weather.list.Select(x => new { day = x.dt_txt, tempMax = x.main.MaximumTemperature, tempMin = x.main.MinimumTemperature })
.OrderBy(x => x.day);
Add the code to the topic friend.
– Victor Laio
@Victorlaio is added
– Matheus
@Leandro Angelo, could you help me with this case ?
– Matheus