Menu
CoddyTech

熟悉 JSON

Coddy 社交媒体搜索项目:Python JSON 基础 课程的第 4 课,共 10 课。

在本课中,我们将熟悉这个社交媒体公司的 JSON 结构,其中包含所有用户/主页的信息。

下面是一个表示员工的 JSON 对象:

{
	"first_name": "Robert",
	"last_name": "Newell",
	"city": "Atlanta",
	"type": "user",
	"gender": "M",
	"country": "United States",
	"job": "Software Engineer"
}

这是数据库中的一条记录,表示某个用户的详细信息。注意,type 设置为user。

现在,我们来看看社交媒体中的另一种实体,也就是主页。

{
	"name": "Friendly Neighborhood Coder",
	"category": "Technology, Education & Engineering",
	"city": "Trivandrum",
	"type": "page",
	"followers": 1080,
	"country": "India",
	"description": "Creator of the YouTube channel - @fncoder. I help python developers level up their skills"
}

你从社交媒体后端服务获取的最终 JSON 是一个记录列表。其中一些是用户记录,另一些是主页记录。这个 JSON 对象列表被放在一个 JSON 数组中,数组名为results。格式如下:

{
	"results": [
		{
			"first_name": "Robert",
			"last_name": "Newell",
			"city": "Atlanta",
			"type": "user",
			"gender": "M",
			"country": "United States",
			"job": "Software Engineer"
		}, {
			"name": "Friendly Neighborhood Coder",
			"category": "Technology, Education & Engineering",
			"city": "Trivandrum",
			"type": "page",
			"followers": 1080,
			"country": "India",
			"description": "Creator of the YouTube channel - @fncoder. I help python developers level up their skills"
		}
	]
}

在本课程的一些挑战中,你会看到上述格式的 JSON 对象。

亲手试试

这节课没有代码挑战。

社交媒体搜索项目:Python JSON 基础中的所有课

自己练习: Python 在线编译器

格式化并浏览任意 JSON: JSON 格式化工具