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


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成为理想的数据交换语言。 易于人阅读和编写,同时也易于机器解析和生成(一般用于提升网络传输速率)。JSON 比 XML 更小、更快,更易解析,所以从Web API和服务端编程语言到NoSQL数据库和客户端框架,都在广泛使用JSON。在不同平台间传递数据方面,JSON已成为XML强有力的替代者。

JSON语法基础

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

语法如下:

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

概述如下:

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

示例1

var jsonData1 = {"name":"lucy","age":18,"isBoy":false};

示例2

var jsonData2 = {
	"student": {
		"name": "lucy",
		"age": 18,
		"isBoy": false
	}
};

示例3

 var jsonData3 = 
 {
	"students": [{
			"name": "wawa",
			"age": 23,
			"isBoy": true
		},
		{
			"name": "tutu",
			"age": 24,
			"isBoy": true
		},
		{
			"name": "lili",
			"age": 25,
			"isBoy": false
		}
	]
};

示例4

var jsonData4 = {
				"key1": "hello", 
				"key2": 55, 
				"key3": [66, "bye", "pi"],
				"key4": {
					"key4_1": 77,
					"key4_2": "ok"
				},
				"key5": [{ 
					"key5_1_1": 88,
					"key5_1_2": "wy"
				}, {
					"key5_2_1": 99,
					"key5_2_2": "pb"
				}]
			};

JSON的本质

JSON到底是什么呢?我们来一起瞅瞅。

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>json</title>
		<script type="text/javascript">
			var jsonData1 = {"name":"lucy","age":18,"isBoy":false};
			alert(jsonData1);
			console.log(jsonData1);
		</script>
	</head>
	<body>
		<h2 id="author" style="color: red;">本文作者:谷哥的小弟</h2>
		<h2 id="blog" style="color: red;">博客地址:http://blog.csdn.net/lfdfhl</h2>
	</body>
</html>

从这里我们可以看到:其实,JSON就是一个JavaScript对象。
在这里插入图片描述

获取JSON对象中的数据

我们常需要依据JSON中的键获取其对应的值,常用方式如下:

  • json格式数据.键名
  • json格式数据[“键名”]

示例1

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>json</title>
		<script type="text/javascript">
			var jsonData4 = {
				"key1": "hello",
				"key2": 55,
				"key3": [66, "bye", "pi"],
				"key4": {
					"key4_1": 77,
					"key4_2": "ok"
				},
				"key5": [{
					"key5_1_1": 88,
					"key5_1_2": "wmd"
				}, {
					"key5_2_1": 99,
					"key5_2_2": "pb"
				}]
			};
			
			var value1=jsonData4.key1;
			//hello
			console.log("value1="+value1);
			
			var value2=jsonData4.key3[1];
			//bye
			console.log("value2="+value2);
			
			var value3=jsonData4.key4.key4_1;
			//77
			console.log("value3="+value3);
			
			var value4=jsonData4.key5[0].key5_1_2;
			//wmd
			console.log("value4="+value4);
			
		</script>
	</head>
	<body>
		<h2 id="author" style="color: red;">本文作者:谷哥的小弟</h2>
		<h2 id="blog" style="color: red;">博客地址:http://blog.csdn.net/lfdfhl</h2>
	</body>
</html>

在这里插入图片描述

示例2

<!DOCTYPE html>
<!-- 本文作者:谷哥的小弟-->
<!-- 博客地址:https://blog.csdn.net/lfdfhl-->
<html>
	<head>
		<meta charset="utf-8">
		<title>JSON</title>
		<script type="text/javascript">
			var jsonData1 = {
				"name": "lucy",
				"age": 18,
				"isBoy": false
			};
			//获取name的值
			var name = jsonData1.name;
			console.log("name=" + name);

			var jsonData2 = {
				"student": {
					"name": "lucy",
					"age": 18,
					"isBoy": false
				}
			};
			//获取age的值
			var age = jsonData2.student.age;
			console.log("age=" + age);

			var jsonData3 = {
				"students": [{
						"name": "wawa",
						"age": 23,
						"isBoy": true
					},
					{
						"name": "tutu",
						"age": 24,
						"isBoy": true
					},
					{
						"name": "lili",
						"age": 25,
						"isBoy": false
					}
				]
			};
			//获取students中第一个元素的isBoy的值
			var isBoy = jsonData3.students[0].isBoy;
			console.log("isBoy=" + isBoy);
			
		</script>
	</head>
	<body>
		<h2 style="color: red;">本文作者:谷哥的小弟</h2>
		<h2 style="color: red;">博客地址:http://blog.csdn.net/lfdfhl</h2>
	</body>
</html>

在这里插入图片描述
除此以外,我们还可使用for循环遍历JSON获取所有的键及其对应的值。

示例3

<!DOCTYPE html>
<!-- 本文作者:谷哥的小弟-->
<!-- 博客地址:https://blog.csdn.net/lfdfhl-->
<html>
	<head>
		<meta charset="utf-8">
		<title>JSON</title>
		<script type="text/javascript">
			var jsonData = {
				"name": "lucy",
				"age": 18,
				"isBoy": false
			};
			//遍历JSON
			for(var k in jsonData){
				var key=k;
				var value=jsonData[k];
				console.log(key+"=" + value);
			}
		</script>
	</head>
	<body>
		<h2 style="color: red;">本文作者:谷哥的小弟</h2>
		<h2 style="color: red;">博客地址:http://blog.csdn.net/lfdfhl</h2>
	</body>
</html>

在这里插入图片描述

JSON数据与Java对象的相互转换

在实际开发中,我们通常需要将JSON数据与Java对象进行相互转换。为提高开发效率常借助于第三方工具进行两者的相互转换,常见的有:Gson、Jsonlib、fastjson、jackson等。在此,以jackson为例进行讲解。

下载jar包

请在jackson官网下载所需jar包,如图所示:
在这里插入图片描述

jackson核心方法

  • ObjectMapper mapper = new ObjectMapper( ):创建mapper
  • mapper.writeValueAsString( ):将Java对象转为JSON字符串
  • mapper.readValue( ):将JSON字符串转换为Java对象

示 例

在这里插入图片描述

Student如下:

package cn.com;
/**
 * 本文作者:谷哥的小弟 
 * 博客地址:http://blog.csdn.net/lfdfhl
 */
public class Student {
	private String name;
	private int age;
	private boolean boy;
	public Student() {
		
	}
	public Student(String name, int age, boolean boy) {
		this.name = name;
		this.age = age;
		this.boy = boy;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public boolean isBoy() {
		return boy;
	}
	public void setBoy(boolean boy) {
		this.boy = boy;
	}
	@Override
	public String toString() {
		return "Student [name=" + name + ", age=" + age + ", boy=" + boy + "]";
	}
	
}

JSONTest如下:

package cn.com;

import java.util.ArrayList;
import java.util.HashMap;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
 * 本文作者:谷哥的小弟 
 * 博客地址:http://blog.csdn.net/lfdfhl
 */
public class JSONTest {

	public static void main(String[] args) {
		try {
			JSONTest jsonTest = new JSONTest();
			jsonTest.test1();
			jsonTest.test2();
			jsonTest.test3();
			jsonTest.test4();
		} catch (Exception e) {
			
		}

	}
	
	//将Java对象转换为JSON字符串
	public void test1() throws Exception{
		Student student=new Student("lucy", 18, false);
		ObjectMapper mapper = new ObjectMapper();
		String jsonString = mapper.writeValueAsString(student);
		//{"name":"lucy","age":18,"boy":false}
		System.out.println(jsonString);
	}
	
	//将List转换为JSON字符串
	public void test2() throws Exception{
		Student student1=new Student("lucy", 18, false);
		Student student2=new Student("tutu", 19, true);
		Student student3=new Student("mrmr", 20, false);
		ArrayList<Student> arrayList=new ArrayList<Student>();
		arrayList.add(student1);
		arrayList.add(student2);
		arrayList.add(student3);
		ObjectMapper mapper = new ObjectMapper();
		String jsonString = mapper.writeValueAsString(arrayList);
		//[{"name":"lucy","age":18,"boy":false},{"name":"tutu","age":19,"boy":true},{"name":"mrmr","age":20,"boy":false}]
		System.out.println(jsonString);
	}
	
	//将Map转换为JSON字符串
	public void test3() throws Exception{
		HashMap<String,Object> hashMap = new HashMap<String,Object>();
		hashMap.put("name", "lucy");
		hashMap.put("age", 17);
		hashMap.put("boy", false);
		ObjectMapper mapper = new ObjectMapper();
		String jsonString = mapper.writeValueAsString(hashMap);
		//{"name":"lucy","age":17,"boy":false}
		System.out.println(jsonString);
	}
	
	//将JSON字符串转为Java对象
	public void test4() throws Exception {
		// {"name":"lucy","age":18,"boy":false}
		String jsonString = "{\"name\":\"lucy\",\"age\":18,\"boy\":false}";
		ObjectMapper mapper = new ObjectMapper();
		Student student = mapper.readValue(jsonString, Student.class);
		//Student [name=lucy, age=18, boy=false]
		System.out.println(student);
	}
}

在这里插入图片描述

JSON数据与字符串的相互转换

JSON的存在有两种形式。

第一种: JSON以对象的形式存在, 亦常称为JSON对象。
第二种: JSON以字符串的形式存在, 亦常称为JSON字符串。

那么,这两形式的JSON在何时使用呢?

在操作JSON中的数据的时常使用JSON对象。
在客户端和服务器之间进行数据交换时常使用JSON字符串。

JSON对象转JSON字符串

使用JSON.stringify( )方法将JSON对象转为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字符串转JSON对象

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

示例如下:

<!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
	}
}

结果如下:
在这里插入图片描述

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

谷哥的小弟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值