ローカルディスクに.jsonデータファイルがあります。Swiftの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
}
はあなたの助けをありがとう!
ポール