【发布时间】:2017-01-10 16:40:51
【问题描述】:
我的本地磁盘上有一个 .json 数据文件。格式如下:
{
"employees" [
{
"Name" : "John",
"Location" : "Austin",
"Age" : "30"
},
.....
],
.....
}
现在我想读取文件并将数据加载到 UITableView 中。我最初的想法是将数据放入一个数组中,并使用该数组来填充表格。但我找不到正确的步骤来实现这一点。
目前我尝试过的方法:
let currentFileURL = URL(string: currentFileString)
do {
let currentData = try Data(contentsOf: currentFileURL!)
let jsonData = try JSONSerialization.jsonObject(with: currentData, options:.allowFragments)
//***********************************************************
//How to proceed here? Or am I using the right methods above?
//***********************************************************
} catch {
//catch the error here
}
感谢您的帮助!
保罗
【问题讨论】: