小言_互联网的博客

讲给后台程序员看的前端系列教程(43)——JSON数据格式及其解析

339人阅读  评论(0)

C语言自学完备手册(33篇)

Android多分辨率适配框架

HTML5前端开发实战系列教程

MySQL数据库实操教程(35篇图文版)

推翻自己和过往——自定义View系列教程(10篇)

走出思维困境,踏上精进之路——Android开发进阶精华录

讲给Android程序员看的前端系列教程(40集免费视频教程+源码)


版权声明

  • 本文原创作者:谷哥的小弟
  • 作者博客地址:http://blog.csdn.net/lfdfhl

JSON概述

JavaScript Object Notation(JavaScript 对象表示法)简称JSON是一种轻量级的数据交换格式。它基于ECMAScript的一个子集。 JSON采用完全独立于语言的文本格式,但是也使用了类似于C语言家族的习惯(包括C、C++、C#、Java、JavaScript、Perl、Python等)。这些特性使JSON成为理想的数据交换语言。 易于人阅读和编写,同时也易于机器解析和生成(一般用于提升网络传输速率)。SON 比 XML 更小、更快,更易解析,所以从Web API和服务端编程语言到NoSQL数据库和客户端框架,都在广泛使用JSON。在不同平台间传递数据方面,JSON已成为XML强有力的替代者。

JSON语法基础

在开发中经常使用JSON保存或传递数据,现对其详细介绍。

语法如下:

{键1:值1,键2:值2,键3:值3,.....}

概述如下:

  • JSON数据以大括号{ }表示
  • 在大括号{ }中以键值对的形式表示数据,各键值对之间以逗号,隔开。其中,键是字符串类型;值是数字、字符串、Boolean值、数组、对象、null中任意一种。
  • 在大括号{ }中各键值对是无序的

示例如下:

{"name":"lucy","age":18}

JSON在JavaScript中的应用

JSON格式在众多主流语言中均有广泛的应用,例如:将JSON字符串转换为对象。在开发过程中我们要注意:JSON只是一种格式而不是对象,不存在所谓的JSON对象。JSON只有字符串形式,就是我们常说的JSON字符串即以键值对和JSON数组形式的字符串。当JSON字符串被转换为Java对象是就是Java对象,当JSON字符串被转换为JavaScript对象时,就是JavaScript对象。

JavaScript对象转JSON字符串

使用JSON.stringify( )方法将JavaScript对象转为JSON字符串

示例如下:

<!DOCTYPE html>
<!-- 本文作者:谷哥的小弟-->
<!-- 博客地址:https://blog.csdn.net/lfdfhl-->
<html>
	<head>
		<meta charset="utf-8">
		<title>JSON</title>
	</head>
	<body>
		<script type="text/javascript">
			var student1={name:"lilei",age:15,height:170.5,isLoveLife:true};
			var jsonData1=JSON.stringify(student1);
			//{"name":"lilei","age":15,"height":170.5,"isLoveLife":true}
			console.log(jsonData1);
			
			//skill是一个数组
			var student2={name:"lilei",age:15,height:170.5,isLoveLife:true, skills:["Java","JavaScript","MySQL"]};
			var jsonData2=JSON.stringify(student2);
			//{"name":"lilei","age":15,"height":170.5,"isLoveLife":true,"skills":["Java","JavaScript","MySQL"]}
			console.log(jsonData2);
			
			//homeAddress是一个对象
			var address={country:"China",province:"sichuang",city:"chengdu",street:"pingan road"};
			var student3={name:"lilei",age:15,height:170.5,isLoveLife:true, homeAddress:address,skills:["Java","JavaScript","MySQL"]};
			var jsonData3=JSON.stringify(student3);
			//{"name":"lilei","age":15,"height":170.5,"isLoveLife":true,"homeAddress":{"country":"China","province":"sichuang","city":"chengdu","street":"pingan road"},"skills":["Java","JavaScript","MySQL"]}
			console.log(jsonData3);
		</script>
	</body>
</html>

结果如下:

JSON字符串转JavaScript对象

使用JSON.parse( )方法将JSON字符串转为JavaScript对象

示例如下:

<!DOCTYPE html>
<!-- 本文作者:谷哥的小弟-->
<!-- 博客地址:https://blog.csdn.net/lfdfhl-->
<html>
	<head>
		<meta charset="utf-8">
		<title>JSON</title>
	</head>
	<body>
		<script type="text/javascript">
			var student;
			var student1={name:"lilei",age:15,height:170.5,isLoveLife:true};
			var jsonData1=JSON.stringify(student1);
			student=JSON.parse(jsonData1);
			console.log(student.name);
			console.log(student.age);
			console.log(student.isLoveLife);
			console.log("------------------------------");
			
		
			var student2={name:"lilei",age:15,height:170.5,isLoveLife:true, skills:["Java","JavaScript","MySQL"]};
			var jsonData2=JSON.stringify(student2);
			student=JSON.parse(jsonData2);
			console.log(student.name);
			console.log(student.age);
			console.log(student.isLoveLife);
			var skillsArray=student.skills;
			console.log(skillsArray);
			for(var i=0;i<skillsArray.length;i++){
				console.log(skillsArray[i]);
			}
			console.log("------------------------------");
			
			var address={country:"China",province:"sichuang",city:"chengdu",street:"pingan road"};
			var student3={name:"lilei",age:15,height:170.5,isLoveLife:true, homeAddress:address,skills:["Java","JavaScript","MySQL"]};
			var jsonData3=JSON.stringify(student3);
			student=JSON.parse(jsonData3);
			console.log(student.name);
			console.log(student.age);
			console.log(student.isLoveLife);
			var skillsArray=student.skills;
			console.log(skillsArray);
			for(var i=0;i<skillsArray.length;i++){
				console.log(skillsArray[i]);
			}
			var addressObject=student.homeAddress;
			console.log(addressObject);
			console.log(addressObject.country);
			console.log(addressObject.province);
			console.log(addressObject.city);
			console.log(addressObject.street);
		</script>
	</body>
</html>

结果如下:

JSON实战

在此,我们利用公开的API发起网络请求获取数据并对其进行解析。

示例如下:

<!DOCTYPE html>
<!-- 本文作者:谷哥的小弟-->
<!-- 博客地址:https://blog.csdn.net/lfdfhl-->
<html>
	<head>
		<meta charset="utf-8">
		<title>JSON</title>
	</head>
	<body>
		<script type="text/javascript">
			//第一步:创建所需的对象
			var httpRequest = new XMLHttpRequest();
			//第二步:打开连接
			httpRequest.open('GET','https://api.openweathermap.org/data/2.5/forecast?q=Beijing,cn&appid=800f49846586c3ba6e7052cfc89af16c', true);
			//第三步:发送请求
			httpRequest.send();
			//第四步:处理结果
			httpRequest.onreadystatechange = function() {
				if (httpRequest.readyState == 4 && httpRequest.status == 200) {
					var weatherJSON = httpRequest.responseText;
					console.log(weatherJSON);
					var weatherObject = JSON.parse(weatherJSON);
					var weather = weatherObject.list[0].weather[0].main;
					var time = weatherObject.list[0].dt_txt;
					console.log(weather);
					console.log(time);
				}
			};
		</script>
	</body>
</html>

数据如下:

{
	"cod": "200",
	"message": 0.0068,
	"cnt": 40,
	"list": [{
		"dt": 1568775600,
		"main": {
			"temp": 297.49,
			"temp_min": 293.6,
			"temp_max": 297.49,
			"pressure": 1028.47,
			"sea_level": 1028.47,
			"grnd_level": 973.29,
			"humidity": 27,
			"temp_kf": 3.89
		},
		"weather": [{
			"id": 800,
			"main": "Clear",
			"description": "clear sky",
			"icon": "01d"
		}],
		"clouds": {
			"all": 0
		},
		"wind": {
			"speed": 1.77,
			"deg": 158.679
		},
		"sys": {
			"pod": "d"
		},
		"dt_txt": "2019-09-18 03:00:00"
	}, {
		"dt": 1568786400,
		"main": {
			"temp": 298.32,
			"temp_min": 295.4,
			"temp_max": 298.32,
			"pressure": 1024.88,
			"sea_level": 1024.88,
			"grnd_level": 970.37,
			"humidity": 27,
			"temp_kf": 2.92
		},
		"weather": [{
			"id": 800,
			"main": "Clear",
			"description": "clear sky",
			"icon": "01d"
		}],
		"clouds": {
			"all": 0
		},
		"wind": {
			"speed": 1.85,
			"deg": 151.647
		},
		"sys": {
			"pod": "d"
		},
		"dt_txt": "2019-09-18 06:00:00"
	}, {
		"dt": 1568797200,
		"main": {
			"temp": 295.18,
			"temp_min": 293.236,
			"temp_max": 295.18,
			"pressure": 1023.67,
			"sea_level": 1023.67,
			"grnd_level": 969.47,
			"humidity": 38,
			"temp_kf": 1.94
		},
		"weather": [{
			"id": 800,
			"main": "Clear",
			"description": "clear sky",
			"icon": "01d"
		}],
		"clouds": {
			"all": 4
		},
		"wind": {
			"speed": 2.2,
			"deg": 182.819
		},
		"sys": {
			"pod": "d"
		},
		"dt_txt": "2019-09-18 09:00:00"
	}, {
		"dt": 1568808000,
		"main": {
			"temp": 288.6,
			"temp_min": 287.624,
			"temp_max": 288.6,
			"pressure": 1025,
			"sea_level": 1025,
			"grnd_level": 970.07,
			"humidity": 52,
			"temp_kf": 0.97
		},
		"weather": [{
			"id": 802,
			"main": "Clouds",
			"description": "scattered clouds",
			"icon": "03n"
		}],
		"clouds": {
			"all": 45
		},
		"wind": {
			"speed": 2.23,
			"deg": 254.819
		},
		"sys": {
			"pod": "n"
		},
		"dt_txt": "2019-09-18 12:00:00"
	}, {
		"dt": 1568818800,
		"main": {
			"temp": 286.976,
			"temp_min": 286.976,
			"temp_max": 286.976,
			"pressure": 1024.24,
			"sea_level": 1024.24,
			"grnd_level": 969.18,
			"humidity": 56,
			"temp_kf": 0
		},
		"weather": [{
			"id": 803,
			"main": "Clouds",
			"description": "broken clouds",
			"icon": "04n"
		}],
		"clouds": {
			"all": 66
		},
		"wind": {
			"speed": 1.55,
			"deg": 259.672
		},
		"sys": {
			"pod": "n"
		},
		"dt_txt": "2019-09-18 15:00:00"
	}, {
		"dt": 1568829600,
		"main": {
			"temp": 286.548,
			"temp_min": 286.548,
			"temp_max": 286.548,
			"pressure": 1023.99,
			"sea_level": 1023.99,
			"grnd_level": 968.85,
			"humidity": 56,
			"temp_kf": 0
		},
		"weather": [{
			"id": 803,
			"main": "Clouds",
			"description": "broken clouds",
			"icon": "04n"
		}],
		"clouds": {
			"all": 83
		},
		"wind": {
			"speed": 0.44,
			"deg": 292.459
		},
		"sys": {
			"pod": "n"
		},
		"dt_txt": "2019-09-18 18:00:00"
	}, {
		"dt": 1568840400,
		"main": {
			"temp": 285.1,
			"temp_min": 285.1,
			"temp_max": 285.1,
			"pressure": 1022.99,
			"sea_level": 1022.99,
			"grnd_level": 967.89,
			"humidity": 61,
			"temp_kf": 0
		},
		"weather": [{
			"id": 804,
			"main": "Clouds",
			"description": "overcast clouds",
			"icon": "04n"
		}],
		"clouds": {
			"all": 100
		},
		"wind": {
			"speed": 0.22,
			"deg": 92.131
		},
		"sys": {
			"pod": "n"
		},
		"dt_txt": "2019-09-18 21:00:00"
	}, {
		"dt": 1568851200,
		"main": {
			"temp": 289.746,
			"temp_min": 289.746,
			"temp_max": 289.746,
			"pressure": 1022.72,
			"sea_level": 1022.72,
			"grnd_level": 967.93,
			"humidity": 46,
			"temp_kf": 0
		},
		"weather": [{
			"id": 804,
			"main": "Clouds",
			"description": "overcast clouds",
			"icon": "04d"
		}],
		"clouds": {
			"all": 100
		},
		"wind": {
			"speed": 0.75,
			"deg": 124.477
		},
		"sys": {
			"pod": "d"
		},
		"dt_txt": "2019-09-19 00:00:00"
	}, {
		"dt": 1568862000,
		"main": {
			"temp": 293.154,
			"temp_min": 293.154,
			"temp_max": 293.154,
			"pressure": 1021.18,
			"sea_level": 1021.18,
			"grnd_level": 966.96,
			"humidity": 41,
			"temp_kf": 0
		},
		"weather": [{
			"id": 804,
			"main": "Clouds",
			"description": "overcast clouds",
			"icon": "04d"
		}],
		"clouds": {
			"all": 100
		},
		"wind": {
			"speed": 1.89,
			"deg": 149.617
		},
		"sys": {
			"pod": "d"
		},
		"dt_txt": "2019-09-19 03:00:00"
	}, {
		"dt": 1568872800,
		"main": {
			"temp": 294.5,
			"temp_min": 294.5,
			"temp_max": 294.5,
			"pressure": 1018.24,
			"sea_level": 1018.24,
			"grnd_level": 964.51,
			"humidity": 43,
			"temp_kf": 0
		},
		"weather": [{
			"id": 804,
			"main": "Clouds",
			"description": "overcast clouds",
			"icon": "04d"
		}],
		"clouds": {
			"all": 100
		},
		"wind": {
			"speed": 1.49,
			"deg": 146.994
		},
		"sys": {
			"pod": "d"
		},
		"dt_txt": "2019-09-19 06:00:00"
	}, {
		"dt": 1568883600,
		"main": {
			"temp": 293.607,
			"temp_min": 293.607,
			"temp_max": 293.607,
			"pressure": 1016.57,
			"sea_level": 1016.57,
			"grnd_level": 962.99,
			"humidity": 55,
			"temp_kf": 0
		},
		"weather": [{
			"id": 804,
			"main": "Clouds",
			"description": "overcast clouds",
			"icon": "04d"
		}],
		"clouds": {
			"all": 100
		},
		"wind": {
			"speed": 1.04,
			"deg": 146.709
		},
		"sys": {
			"pod": "d"
		},
		"dt_txt": "2019-09-19 09:00:00"
	}, {
		"dt": 1568894400,
		"main": {
			"temp": 289.7,
			"temp_min": 289.7,
			"temp_max": 289.7,
			"pressure": 1018.51,
			"sea_level": 1018.51,
			"grnd_level": 963.99,
			"humidity": 66,
			"temp_kf": 0
		},
		"weather": [{
			"id": 804,
			"main": "Clouds",
			"description": "overcast clouds",
			"icon": "04n"
		}],
		"clouds": {
			"all": 100
		},
		"wind": {
			"speed": 1.09,
			"deg": 259.319
		},
		"sys": {
			"pod": "n"
		},
		"dt_txt": "2019-09-19 12:00:00"
	}, {
		"dt": 1568905200,
		"main": {
			"temp": 288.42,
			"temp_min": 288.42,
			"temp_max": 288.42,
			"pressure": 1017.59,
			"sea_level": 1017.59,
			"grnd_level": 962.96,
			"humidity": 67,
			"temp_kf": 0
		},
		"weather": [{
			"id": 804,
			"main": "Clouds",
			"description": "overcast clouds",
			"icon": "04n"
		}],
		"clouds": {
			"all": 100
		},
		"wind": {
			"speed": 0.08,
			"deg": 309.806
		},
		"sys": {
			"pod": "n"
		},
		"dt_txt": "2019-09-19 15:00:00"
	}, {
		"dt": 1568916000,
		"main": {
			"temp": 288.3,
			"temp_min": 288.3,
			"temp_max": 288.3,
			"pressure": 1016.62,
			"sea_level": 1016.62,
			"grnd_level": 962.03,
			"humidity": 67,
			"temp_kf": 0
		},
		"weather": [{
			"id": 804,
			"main": "Clouds",
			"description": "overcast clouds",
			"icon": "04n"
		}],
		"clouds": {
			"all": 100
		},
		"wind": {
			"speed": 0.46,
			"deg": 308.718
		},
		"sys": {
			"pod": "n"
		},
		"dt_txt": "2019-09-19 18:00:00"
	}, {
		"dt": 1568926800,
		"main": {
			"temp": 288.914,
			"temp_min": 288.914,
			"temp_max": 288.914,
			"pressure": 1016.51,
			"sea_level": 1016.51,
			"grnd_level": 961.95,
			"humidity": 63,
			"temp_kf": 0
		},
		"weather": [{
			"id": 804,
			"main": "Clouds",
			"description": "overcast clouds",
			"icon": "04n"
		}],
		"clouds": {
			"all": 100
		},
		"wind": {
			"speed": 0.6,
			"deg": 32.259
		},
		"sys": {
			"pod": "n"
		},
		"dt_txt": "2019-09-19 21:00:00"
	}, {
		"dt": 1568937600,
		"main": {
			"temp": 291.043,
			"temp_min": 291.043,
			"temp_max": 291.043,
			"pressure": 1017.65,
			"sea_level": 1017.65,
			"grnd_level": 963.6,
			"humidity": 58,
			"temp_kf": 0
		},
		"weather": [{
			"id": 804,
			"main": "Clouds",
			"description": "overcast clouds",
			"icon": "04d"
		}],
		"clouds": {
			"all": 100
		},
		"wind": {
			"speed": 1.5,
			"deg": 200.722
		},
		"sys": {
			"pod": "d"
		},
		"dt_txt": "2019-09-20 00:00:00"
	}, {
		"dt": 1568948400,
		"main": {
			"temp": 295.213,
			"temp_min": 295.213,
			"temp_max": 295.213,
			"pressure": 1017.07,
			"sea_level": 1017.07,
			"grnd_level": 963.41,
			"humidity": 41,
			"temp_kf": 0
		},
		"weather": [{
			"id": 804,
			"main": "Clouds",
			"description": "overcast clouds",
			"icon": "04d"
		}],
		"clouds": {
			"all": 100
		},
		"wind": {
			"speed": 3.03,
			"deg": 265.007
		},
		"sys": {
			"pod": "d"
		},
		"dt_txt": "2019-09-20 03:00:00"
	}, {
		"dt": 1568959200,
		"main": {
			"temp": 297.3,
			"temp_min": 297.3,
			"temp_max": 297.3,
			"pressure": 1016.19,
			"sea_level": 1016.19,
			"grnd_level": 962.09,
			"humidity": 31,
			"temp_kf": 0
		},
		"weather": [{
			"id": 804,
			"main": "Clouds",
			"description": "overcast clouds",
			"icon": "04d"
		}],
		"clouds": {
			"all": 97
		},
		"wind": {
			"speed": 2.22,
			"deg": 210.822
		},
		"sys": {
			"pod": "d"
		},
		"dt_txt": "2019-09-20 06:00:00"
	}, {
		"dt": 1568970000,
		"main": {
			"temp": 295.7,
			"temp_min": 295.7,
			"temp_max": 295.7,
			"pressure": 1016.5,
			"sea_level": 1016.5,
			"grnd_level": 962.07,
			"humidity": 41,
			"temp_kf": 0
		},
		"weather": [{
			"id": 804,
			"main": "Clouds",
			"description": "overcast clouds",
			"icon": "04d"
		}],
		"clouds": {
			"all": 100
		},
		"wind": {
			"speed": 1.31,
			"deg": 170.566
		},
		"sys": {
			"pod": "d"
		},
		"dt_txt": "2019-09-20 09:00:00"
	}, {
		"dt": 1568980800,
		"main": {
			"temp": 291,
			"temp_min": 291,
			"temp_max": 291,
			"pressure": 1018.39,
			"sea_level": 1018.39,
			"grnd_level": 963.71,
			"humidity": 50,
			"temp_kf": 0
		},
		"weather": [{
			"id": 804,
			"main": "Clouds",
			"description": "overcast clouds",
			"icon": "04n"
		}],
		"clouds": {
			"all": 100
		},
		"wind": {
			"speed": 2.13,
			"deg": 253.177
		},
		"sys": {
			"pod": "n"
		},
		"dt_txt": "2019-09-20 12:00:00"
	}, {
		"dt": 1568991600,
		"main": {
			"temp": 288.9,
			"temp_min": 288.9,
			"temp_max": 288.9,
			"pressure": 1019.73,
			"sea_level": 1019.73,
			"grnd_level": 964.81,
			"humidity": 58,
			"temp_kf": 0
		},
		"weather": [{
			"id": 804,
			"main": "Clouds",
			"description": "overcast clouds",
			"icon": "04n"
		}],
		"clouds": {
			"all": 100
		},
		"wind": {
			"speed": 1.26,
			"deg": 281.194
		},
		"sys": {
			"pod": "n"
		},
		"dt_txt": "2019-09-20 15:00:00"
	}, {
		"dt": 1569002400,
		"main": {
			"temp": 287.921,
			"temp_min": 287.921,
			"temp_max": 287.921,
			"pressure": 1019.95,
			"sea_level": 1019.95,
			"grnd_level": 965.11,
			"humidity": 65,
			"temp_kf": 0
		},
		"weather": [{
			"id": 804,
			"main": "Clouds",
			"description": "overcast clouds",
			"icon": "04n"
		}],
		"clouds": {
			"all": 100
		},
		"wind": {
			"speed": 1.06,
			"deg": 345.415
		},
		"sys": {
			"pod": "n"
		},
		"dt_txt": "2019-09-20 18:00:00"
	}, {
		"dt": 1569013200,
		"main": {
			"temp": 287.339,
			"temp_min": 287.339,
			"temp_max": 287.339,
			"pressure": 1020.6,
			"sea_level": 1020.6,
			"grnd_level": 965.69,
			"humidity": 67,
			"temp_kf": 0
		},
		"weather": [{
			"id": 801,
			"main": "Clouds",
			"description": "few clouds",
			"icon": "02n"
		}],
		"clouds": {
			"all": 22
		},
		"wind": {
			"speed": 1.32,
			"deg": 305.195
		},
		"sys": {
			"pod": "n"
		},
		"dt_txt": "2019-09-20 21:00:00"
	}, {
		"dt": 1569024000,
		"main": {
			"temp": 292.314,
			"temp_min": 292.314,
			"temp_max": 292.314,
			"pressure": 1021.83,
			"sea_level": 1021.83,
			"grnd_level": 967.08,
			"humidity": 51,
			"temp_kf": 0
		},
		"weather": [{
			"id": 801,
			"main": "Clouds",
			"description": "few clouds",
			"icon": "02d"
		}],
		"clouds": {
			"all": 12
		},
		"wind": {
			"speed": 0.77,
			"deg": 324.28
		},
		"sys": {
			"pod": "d"
		},
		"dt_txt": "2019-09-21 00:00:00"
	}, {
		"dt": 1569034800,
		"main": {
			"temp": 297.2,
			"temp_min": 297.2,
			"temp_max": 297.2,
			"pressure": 1020.99,
			"sea_level": 1020.99,
			"grnd_level": 966.75,
			"humidity": 37,
			"temp_kf": 0
		},
		"weather": [{
			"id": 800,
			"main": "Clear",
			"description": "clear sky",
			"icon": "01d"
		}],
		"clouds": {
			"all": 0
		},
		"wind": {
			"speed": 1.57,
			"deg": 77.91
		},
		"sys": {
			"pod": "d"
		},
		"dt_txt": "2019-09-21 03:00:00"
	}, {
		"dt": 1569045600,
		"main": {
			"temp": 298.6,
			"temp_min": 298.6,
			"temp_max": 298.6,
			"pressure": 1019.11,
			"sea_level": 1019.11,
			"grnd_level": 965.39,
			"humidity": 32,
			"temp_kf": 0
		},
		"weather": [{
			"id": 800,
			"main": "Clear",
			"description": "clear sky",
			"icon": "01d"
		}],
		"clouds": {
			"all": 0
		},
		"wind": {
			"speed": 2.15,
			"deg": 102.555
		},
		"sys": {
			"pod": "d"
		},
		"dt_txt": "2019-09-21 06:00:00"
	}, {
		"dt": 1569056400,
		"main": {
			"temp": 297.3,
			"temp_min": 297.3,
			"temp_max": 297.3,
			"pressure": 1018.92,
			"sea_level": 1018.92,
			"grnd_level": 965.2,
			"humidity": 37,
			"temp_kf": 0
		},
		"weather": [{
			"id": 800,
			"main": "Clear",
			"description": "clear sky",
			"icon": "01d"
		}],
		"clouds": {
			"all": 0
		},
		"wind": {
			"speed": 1.48,
			"deg": 151.959
		},
		"sys": {
			"pod": "d"
		},
		"dt_txt": "2019-09-21 09:00:00"
	}, {
		"dt": 1569067200,
		"main": {
			"temp": 290.6,
			"temp_min": 290.6,
			"temp_max": 290.6,
			"pressure": 1020.33,
			"sea_level": 1020.33,
			"grnd_level": 966.2,
			"humidity": 61,
			"temp_kf": 0
		},
		"weather": [{
			"id": 800,
			"main": "Clear",
			"description": "clear sky",
			"icon": "01n"
		}],
		"clouds": {
			"all": 0
		},
		"wind": {
			"speed": 2.02,
			"deg": 263.503
		},
		"sys": {
			"pod": "n"
		},
		"dt_txt": "2019-09-21 12:00:00"
	}, {
		"dt": 1569078000,
		"main": {
			"temp": 289.781,
			"temp_min": 289.781,
			"temp_max": 289.781,
			"pressure": 1020.93,
			"sea_level": 1020.93,
			"grnd_level": 966.39,
			"humidity": 60,
			"temp_kf": 0
		},
		"weather": [{
			"id": 800,
			"main": "Clear",
			"description": "clear sky",
			"icon": "01n"
		}],
		"clouds": {
			"all": 2
		},
		"wind": {
			"speed": 1.68,
			"deg": 293.821
		},
		"sys": {
			"pod": "n"
		},
		"dt_txt": "2019-09-21 15:00:00"
	}, {
		"dt": 1569088800,
		"main": {
			"temp": 289.596,
			"temp_min": 289.596,
			"temp_max": 289.596,
			"pressure": 1020.6,
			"sea_level": 1020.6,
			"grnd_level": 965.87,
			"humidity": 62,
			"temp_kf": 0
		},
		"weather": [{
			"id": 801,
			"main": "Clouds",
			"description": "few clouds",
			"icon": "02n"
		}],
		"clouds": {
			"all": 23
		},
		"wind": {
			"speed": 0.99,
			"deg": 348.587
		},
		"sys": {
			"pod": "n"
		},
		"dt_txt": "2019-09-21 18:00:00"
	}, {
		"dt": 1569099600,
		"main": {
			"temp": 286.792,
			"temp_min": 286.792,
			"temp_max": 286.792,
			"pressure": 1020.87,
			"sea_level": 1020.87,
			"grnd_level": 966.35,
			"humidity": 69,
			"temp_kf": 0
		},
		"weather": [{
			"id": 800,
			"main": "Clear",
			"description": "clear sky",
			"icon": "01n"
		}],
		"clouds": {
			"all": 0
		},
		"wind": {
			"speed": 1.47,
			"deg": 0.429
		},
		"sys": {
			"pod": "n"
		},
		"dt_txt": "2019-09-21 21:00:00"
	}, {
		"dt": 1569110400,
		"main": {
			"temp": 293.017,
			"temp_min": 293.017,
			"temp_max": 293.017,
			"pressure": 1021.55,
			"sea_level": 1021.55,
			"grnd_level": 966.99,
			"humidity": 48,
			"temp_kf": 0
		},
		"weather": [{
			"id": 800,
			"main": "Clear",
			"description": "clear sky",
			"icon": "01d"
		}],
		"clouds": {
			"all": 0
		},
		"wind": {
			"speed": 1.78,
			"deg": 311.973
		},
		"sys": {
			"pod": "d"
		},
		"dt_txt": "2019-09-22 00:00:00"
	}, {
		"dt": 1569121200,
		"main": {
			"temp": 299.661,
			"temp_min": 299.661,
			"temp_max": 299.661,
			"pressure": 1020.16,
			"sea_level": 1020.16,
			"grnd_level": 966.22,
			"humidity": 25,
			"temp_kf": 0
		},
		"weather": [{
			"id": 800,
			"main": "Clear",
			"description": "clear sky",
			"icon": "01d"
		}],
		"clouds": {
			"all": 0
		},
		"wind": {
			"speed": 2.02,
			"deg": 8.615
		},
		"sys": {
			"pod": "d"
		},
		"dt_txt": "2019-09-22 03:00:00"
	}, {
		"dt": 1569132000,
		"main": {
			"temp": 300.7,
			"temp_min": 300.7,
			"temp_max": 300.7,
			"pressure": 1017.96,
			"sea_level": 1017.96,
			"grnd_level": 964.49,
			"humidity": 20,
			"temp_kf": 0
		},
		"weather": [{
			"id": 800,
			"main": "Clear",
			"description": "clear sky",
			"icon": "01d"
		}],
		"clouds": {
			"all": 0
		},
		"wind": {
			"speed": 2.29,
			"deg": 349.359
		},
		"sys": {
			"pod": "d"
		},
		"dt_txt": "2019-09-22 06:00:00"
	}, {
		"dt": 1569142800,
		"main": {
			"temp": 299.3,
			"temp_min": 299.3,
			"temp_max": 299.3,
			"pressure": 1017.37,
			"sea_level": 1017.37,
			"grnd_level": 963.81,
			"humidity": 30,
			"temp_kf": 0
		},
		"weather": [{
			"id": 803,
			"main": "Clouds",
			"description": "broken clouds",
			"icon": "04d"
		}],
		"clouds": {
			"all": 54
		},
		"wind": {
			"speed": 0.88,
			"deg": 295.343
		},
		"sys": {
			"pod": "d"
		},
		"dt_txt": "2019-09-22 09:00:00"
	}, {
		"dt": 1569153600,
		"main": {
			"temp": 292.235,
			"temp_min": 292.235,
			"temp_max": 292.235,
			"pressure": 1019.27,
			"sea_level": 1019.27,
			"grnd_level": 965.02,
			"humidity": 38,
			"temp_kf": 0
		},
		"weather": [{
			"id": 802,
			"main": "Clouds",
			"description": "scattered clouds",
			"icon": "03n"
		}],
		"clouds": {
			"all": 29
		},
		"wind": {
			"speed": 1.9,
			"deg": 278.535
		},
		"sys": {
			"pod": "n"
		},
		"dt_txt": "2019-09-22 12:00:00"
	}, {
		"dt": 1569164400,
		"main": {
			"temp": 291.99,
			"temp_min": 291.99,
			"temp_max": 291.99,
			"pressure": 1019.96,
			"sea_level": 1019.96,
			"grnd_level": 965.07,
			"humidity": 36,
			"temp_kf": 0
		},
		"weather": [{
			"id": 803,
			"main": "Clouds",
			"description": "broken clouds",
			"icon": "04n"
		}],
		"clouds": {
			"all": 78
		},
		"wind": {
			"speed": 2.37,
			"deg": 279.546
		},
		"sys": {
			"pod": "n"
		},
		"dt_txt": "2019-09-22 15:00:00"
	}, {
		"dt": 1569175200,
		"main": {
			"temp": 287.492,
			"temp_min": 287.492,
			"temp_max": 287.492,
			"pressure": 1020.62,
			"sea_level": 1020.62,
			"grnd_level": 966.33,
			"humidity": 74,
			"temp_kf": 0
		},
		"weather": [{
			"id": 802,
			"main": "Clouds",
			"description": "scattered clouds",
			"icon": "03n"
		}],
		"clouds": {
			"all": 46
		},
		"wind": {
			"speed": 1.76,
			"deg": 35.632
		},
		"sys": {
			"pod": "n"
		},
		"dt_txt": "2019-09-22 18:00:00"
	}, {
		"dt": 1569186000,
		"main": {
			"temp": 286.319,
			"temp_min": 286.319,
			"temp_max": 286.319,
			"pressure": 1021.72,
			"sea_level": 1021.72,
			"grnd_level": 967.35,
			"humidity": 85,
			"temp_kf": 0
		},
		"weather": [{
			"id": 800,
			"main": "Clear",
			"description": "clear sky",
			"icon": "01n"
		}],
		"clouds": {
			"all": 0
		},
		"wind": {
			"speed": 1.45,
			"deg": 358.3
		},
		"sys": {
			"pod": "n"
		},
		"dt_txt": "2019-09-22 21:00:00"
	}, {
		"dt": 1569196800,
		"main": {
			"temp": 292.157,
			"temp_min": 292.157,
			"temp_max": 292.157,
			"pressure": 1022.9,
			"sea_level": 1022.9,
			"grnd_level": 968.41,
			"humidity": 50,
			"temp_kf": 0
		},
		"weather": [{
			"id": 800,
			"main": "Clear",
			"description": "clear sky",
			"icon": "01d"
		}],
		"clouds": {
			"all": 0
		},
		"wind": {
			"speed": 1.09,
			"deg": 27.484
		},
		"sys": {
			"pod": "d"
		},
		"dt_txt": "2019-09-23 00:00:00"
	}],
	"city": {
		"id": 1816670,
		"name": "Beijing",
		"coord": {
			"lat": 39.906,
			"lon": 116.3912
		},
		"country": "CN",
		"population": 1000000,
		"timezone": 28800,
		"sunrise": 1568757453,
		"sunset": 1568802019
	}
}

结果如下:


转载:https://blog.csdn.net/lfdfhl/article/details/100938299
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场