In this tutorial, we will learn how to parse a JSON response in our iOS Application using Swift. We will display the parsed response in a UITableView. To know more about UITableView, check out this tutorial before proceeding ahead.
在本教程中,我们将学习如何使用Swift在我们的iOS应用程序中解析JSON响应。 我们将在UITableView中显示已解析的响应。 要了解有关UITableView的更多信息,请先阅读本教程,然后再继续。
Swift JSON解析 (Swift JSON Parsing)
JSON is the most commonly used format to send and receive data from the web services. The data is in the form of key-value pairs. Using Swift Dictionaries we can easily fetch the values from the keys.
JSON是最常用的从Web服务发送和接收数据的格式。 数据采用键值对的形式。 使用Swift字典,我们可以轻松地从键中获取值。
In this tutorial, we’ll be parsing JSON data from a local resource file.
在本教程中,我们将从本地资源文件中解析JSON数据。
The JSONSerialization
class is used to parse a JSON data into a dictionary of key-value pairs by converting the Data
object.
JSONSerialization
类用于通过转换Data
对象将JSON数据解析为键值对字典。
The type of a JSON data is [String: Any]
.
JSON数据的类型为[String: Any]
。
Let’s create a single view iOS Application in which we’ll parse the data from a locally created JSON file into the TableView.
让我们创建一个单视图iOS应用程序,在其中将本地创建的JSON文件中的数据解析为TableView。