在javascript中过滤json数组
我从一个气象服务获取以下Json数据。我需要一个JavaScript函数来过滤掉每个dt_txt的最高main.temp数组 示例:我有5天的数据,每天有8条记录。我需要一张每天最高温度的记录。我们将非常感谢您的帮助在javascript中过滤json数组,javascript,json,filter,Javascript,Json,Filter,我从一个气象服务获取以下Json数据。我需要一个JavaScript函数来过滤掉每个dt_txt的最高main.temp数组 示例:我有5天的数据,每天有8条记录。我需要一张每天最高温度的记录。我们将非常感谢您的帮助 [{ "dt":1475355600, "main":{ "temp":294.22, "temp_min":294.22, "temp_max":295.309, "pressure":1009.36,
[{ "dt":1475355600,
"main":{
"temp":294.22,
"temp_min":294.22,
"temp_max":295.309,
"pressure":1009.36,
"sea_level":1021.34,
"grnd_level":1009.36,
"humidity":52,
"temp_kf":-1.09
},
"weather":[
{
"id":800,
"main":"Clear",
"description":"clear sky",
"icon":"01n"
}
],
"clouds":{
"all":0
},
"wind":{
"speed":1.27,
"deg":285.503
},
"sys":{
"pod":"n"
},
"dt_txt":"2016-10-01 21:00:00"
},
{
"dt":1475366400,
"main":{
"temp":293.49,
"temp_min":293.49,
"temp_max":294.306,
"pressure":1009.32,
"sea_level":1021.42,
"grnd_level":1009.32,
"humidity":57,
"temp_kf":-0.82
},
"weather":[
{
"id":800,
"main":"Clear",
"description":"clear sky",
"icon":"01n"
}
],
"clouds":{
"all":0
},
"wind":{
"speed":1.22,
"deg":349.001
},
"sys":{
"pod":"n"
},
"dt_txt":"2016-10-02 00:00:00"
},
{
"dt":1475377200,
"main":{
"temp":293.13,
"temp_min":293.13,
"temp_max":293.672,
"pressure":1011.03,
"sea_level":1023.03,
"grnd_level":1011.03,
"humidity":61,
"temp_kf":-0.55
},
"weather":[
{
"id":800,
"main":"Clear",
"description":"clear sky",
"icon":"01d"
}
],
"clouds":{
"all":0
},
"wind":{
"speed":1.42,
"deg":6.50092
},
"sys":{
"pod":"d"
},
"dt_txt":"2016-10-02 03:00:00"
},
{
"dt":1475388000,
"main":{
"temp":300.82,
"temp_min":300.82,
"temp_max":301.096,
"pressure":1012.55,
"sea_level":1024.46,
"grnd_level":1012.55,
"humidity":72,
"temp_kf":-0.27
},
"weather":[
{
"id":800,
"main":"Clear",
"description":"clear sky",
"icon":"01d"
}
],
"clouds":{
"all":0
},
"wind":{
"speed":2.06,
"deg":10.5145
},
"sys":{
"pod":"d"
},
"dt_txt":"2016-10-02 06:00:00"
},
{
"dt":1475398800,
"main":{
"temp":304.139,
"temp_min":304.139,
"temp_max":304.139,
"pressure":1011.34,
"sea_level":1023.24,
"grnd_level":1011.34,
"humidity":70,
"temp_kf":0
},
"weather":[
{
"id":800,
"main":"Clear",
"description":"clear sky",
"icon":"01d"
}
],
"clouds":{
"all":0
},
"wind":{
"speed":2.96,
"deg":15.0044
},
"sys":{
"pod":"d"
},
"dt_txt":"2016-10-02 09:00:00"
},
{
"dt":1475409600,
"main":{
"temp":305.239,
"temp_min":305.239,
"temp_max":305.239,
"pressure":1009.96,
"sea_level":1021.78,
"grnd_level":1009.96,
"humidity":52,
"temp_kf":0
},
"weather":[
{
"id":800,
"main":"Clear",
"description":"clear sky",
"icon":"01d"
}
],
"clouds":{
"all":0
},
"wind":{
"speed":4.06,
"deg":21.503
},
"sys":{
"pod":"d"
},
"dt_txt":"2016-10-02 12:00:00"
},
{
"dt":1475560800,
"main":{
"temp":300.429,
"temp_min":300.429,
"temp_max":300.429,
"pressure":1012.43,
"sea_level":1024.37,
"grnd_level":1012.43,
"humidity":74,
"temp_kf":0
},
"weather":[
{
"id":800,
"main":"Clear",
"description":"clear sky",
"icon":"01d"
}
],
"clouds":{
"all":0
},
"wind":{
"speed":2.1,
"deg":292.503
},
"sys":{
"pod":"d"
},
"dt_txt":"2016-10-04 06:00:00"
},
{
"dt":1475571600,
"main":{
"temp":304.116,
"temp_min":304.116,
"temp_max":304.116,
"pressure":1011.18,
"sea_level":1023,
"grnd_level":1011.18,
"humidity":70,
"temp_kf":0
},
"weather":[
{
"id":800,
"main":"Clear",
"description":"clear sky",
"icon":"01d"
}
],
"clouds":{
"all":0
},
"wind":{
"speed":2.21,
"deg":316.5
},
"sys":{
"pod":"d"
},
"dt_txt":"2016-10-04 09:00:00"
},
{
"dt":1475582400,
"main":{
"temp":305.353,
"temp_min":305.353,
"temp_max":305.353,
"pressure":1009.66,
"sea_level":1021.39,
"grnd_level":1009.66,
"humidity":49,
"temp_kf":0
},
"weather":[
{
"id":800,
"main":"Clear",
"description":"clear sky",
"icon":"01d"
}
],
"clouds":{
"all":0
},
"wind":{
"speed":2.39,
"deg":346.503
},
"sys":{
"pod":"d"
},
"dt_txt":"2016-10-04 12:00:00"
},
{
"dt":1475593200,
"main":{
"temp":300.609,
"temp_min":300.609,
"temp_max":300.609,
"pressure":1009.85,
"sea_level":1021.74,
"grnd_level":1009.85,
"humidity":45,
"temp_kf":0
},
"weather":[
{
"id":800,
"main":"Clear",
"description":"clear sky",
"icon":"01n"
}
],
"clouds":{
"all":0
},
"wind":{
"speed":1.68,
"deg":16.0005
},
"sys":{
"pod":"n"
},
"dt_txt":"2016-10-04 15:00:00"
},
{
"dt":1475604000,
"main":{
"temp":296.264,
"temp_min":296.264,
"temp_max":296.264,
"pressure":1010.76,
"sea_level":1022.71,
"grnd_level":1010.76,
"humidity":51,
"temp_kf":0
},
"weather":[
{
"id":800,
"main":"Clear",
"description":"clear sky",
"icon":"01n"
}
],
"clouds":{
"all":0
},
"wind":{
"speed":1.48,
"deg":85.0018
},
"sys":{
"pod":"n"
},
"dt_txt":"2016-10-04 18:00:00"
},
{
"dt":1475614800,
"main":{
"temp":294.28,
"temp_min":294.28,
"temp_max":294.28,
"pressure":1010.2,
"sea_level":1022.3,
"grnd_level":1010.2,
"humidity":56,
"temp_kf":0
},
"weather":[
{
"id":800,
"main":"Clear",
"description":"clear sky",
"icon":"01n"
}
],
"clouds":{
"all":0
},
"wind":{
"speed":1.27,
"deg":123.501
},
"sys":{
"pod":"n"
},
"dt_txt":"2016-10-04 21:00:00"
}]
您可以使用一个日期哈希表,并在迭代中获得最大值
var数据=[{dt:1475355600,main:{temp:294.22,temp\u min:294.22,temp\u max:295.309,气压:1009.36,海平面:1021.34,地面:1009.36,湿度:52,temp\u kf:-1.09},天气:[{id:800,main:“晴朗”,说明:“晴朗的天空”,图标:“01n}],云:{all:0},风速:1.27,摄氏度:285.503,系统:{“2016-10-01 21:00:00”{dt:1475366400,主要:{temp:293.49,temp\u min:293.49,temp\u max:294.306,气压:1009.32,海平面:1021.42,地面:1009.32,湿度:57,温度-0.82},天气:[{id:800,主要:“晴朗”,描述:“晴朗的天空”,图标:“01n}],云:{all:0},风速:1.22,系统:349.001:{,dt_txt:“2016-10-02 00:00:00”},{dt:1475377200,main:{temp:293.13,temp_min:293.13,temp_max:293.672,气压:1011.03,海平面:1023.03,地面:1011.03,湿度:61,温度kf:-0.55},天气:[{id:800,main:“晴朗”,描述:“晴朗的天空”,图标:“01d”},云层:{all:0,风速:1.42度,系统:5006度:{pod:'d},dt_txt:'2016-10-02 03:00:00},{dt:1475388000,main:{temp:300.82,temp_min:300.82,temp_max:301.096,气压:1012.55,海平面:1024.46,地面:1012.55,湿度:72,温度kf:-0.27},天气:[{id:800,main:“晴朗”,说明:“晴朗的天空”,图标:“01d”},云层:{all:0},风速:2.5106,风速:10.45},系统:{pod:“d”},dt_txt:“2016-10-02 06:00:00”},{dt:1475398800,main:{temp:304.139,temp:304.139,temp_min:304.139,temp_max:304.139,气压:1011.34,海平面:1023.24,地面平面:1011.34,湿度:70,temp_-kf:0},天气:[{id:800,main:“晴朗”,说明:“晴朗的天空”,图标:“01d”},云层:{all:0},风:速度:2.96度:15.0044度,系统:{pod:“d”},dt_txt:“2016-10-02 09:00:00”},{dt:1475409600,主要:{temp:305.239,temp_min:305.239,temp_max:305.239,压力:1009.96,海平面:1021.78,grnd_平面:1009.96,湿度:52,temp_kf:0},天气:[{id:800,主要:“晴朗”,描述:“晴朗的天空”,图标:“01d”},云彩:{,风速:4.06度:21.503度,气压:1012.43度,海平面:1024.37度,地面高度:1012.43度,湿度:74度,温度:0度,天气:[{id:800,主要:“晴朗”,描述:“晴朗的天空”,图标:“01d”,云彩:{all:0},风:{speed:2.1,deg:292.503},sys:{pod:d},dtu-txt:“2016-10-04 06:00:00},{dt:1475571600,main:{temp:304.116,temp\u-min:304.116,temp\u-max:304.116,压力:1011.18,海平面:1023,地面标高:1011.18,湿度:70,temp\u-kf:0},天气:[id:800,main:“晴朗”,图标描述:“晴朗的天空”}],云:{all:0},风:{speed:2.21,deg:316.5},系统:{pod:d},dtu-txt:{dt:1475582400,main:{temp:305.353,temp\u-min:305.353,temp\u-max:305.353,压力:1009.66,海平面:1021.39,地面标高:1009.66,湿度:49,temp\u-kf:0},天气:{id:800,主景:“晴朗”,说明:“晴朗”云:{all:0},风:{speed:2.39,deg:346.503},系统:{pod:d},dtu-txt:2016-10-04 12:00:00},{dt:1475593200,main:{temp:300.609,temp\u-min:300.609,temp\u-max:300.609,气压:1009.85,海平面:1021.74,地面:1009.85,湿度:45,temp\u-kf:0},天气:{id:800,天空晴朗,{云:{all:0},风:{speed:1.68,deg:16.0005},系统:{pod:n},dtu-txt:2016-10-04 15:00:00},{dt:1475604000,main:{temp:296.264,temp\u-min:296.264,temp\u-max:296.264,气压:1010.76,海平面:1022.71,地面:1010.76,湿度:51,temp\u-kf:0,天气:800,{“晴空”,图标:“01n”}),云:{all:0},风:{speed:1.48,deg:85.0018},系统:{pod:n},dtu-txt:“2016-10-04 18:00:00”},{dt:1475614800,main:{temp:294.28,temp\u min:294.28,temp\u max:294.28,气压:1010.2,海平面:1022.3,地面:1010.2,湿度:56,temp\u-kf:0,天气:晴朗,{:800晴朗的天空,图标:“01n”},云:{all:0},风:{speed:1.27,deg:123.501},系统:{pod:n},dt_txt:“2016-10-04 21:00:00”},
结果=[];
data.forEach(函数(a){
变量日期=a.dt_txt.slice(0,10);
如果(!此[日期]){
此[日期]={date:date,max:-无限};
结果推送(本[日期]);
}
此[date].max=Math.max(此[date].max,a.main.temp);
},Object.create(null));
console.log(结果);
.as控制台包装{max height:100%!important;top:0;}
结果应该如何?您尝试了什么?我们确实不需要json转储。只需包含相关属性和“。。。“或者排除其余部分。另外,请向我们展示您已经尝试使用的代码。非常感谢Nina的努力和快速响应。