iOS 解碼 & 編碼 JSON 的文章整理

利用 JSONDecoder 和 Codable 解析 JSON 和生成自訂型別資料

利用 Smart JSON Editor 查看 JSON 的資料型別

解析 JSON 時,Decodable 型別加 ? 的情況

顯示美美 JSON 的 JSON Editor Online

找出 JSONDecoder 的 decode 錯誤

利用 JSONSerialization 印出美美縮排的 JSON

利用中斷點將 JSON Data 變成字串

利用 keyDecodingStrategy 的 convertFromSnakeCase 自動轉換 JSON 欄位名稱

利用 CodingKey 客製 JSON 對應的 property

自訂 custom 的 keyDecodingStrategy,將 JSON 的大寫 key 變小寫

JSONDecoder 解析時間的 DateDecodingStrategy

讀取專案裡的檔案測試 JSON 解碼

利用 Swift Error Breakpoint 檢查 error handling 丟出的錯誤

利用 Postman,Development Assets & Code snippet 驗證 Codable 型別

定義 Decodable 的 init(from:) 解析 JSON

在 Codable 型別裡宣告跟 JSON 資料無關的 property

貼上 JSON,自動產生 Swift Codable 型別的 quicktype

使用 google 表單製作 iOS App 開發練習的假資料 array

方便 App 測試假(mock)的 JSON 資料的平台

使用 Mac 當後台,存放測試的圖片和 JSON

利用 JSONDecoder 將資料變成遵從 Decodable 的 enum

利用 CodingKey & init(from:) 將不同的 JSON key 對應到同一個 property

透過 init(from:) 解析 JSON 裡包裝成字串的 array 或 dictionary

透過 encode(to:) 將 JSON 裡的 array 或物件變成字串上傳

開啟很大的 JSON 檔的軟體 — Dadroit JSON Viewer

其它參考資源

--

--

彼得潘的 iOS App Neverland
彼得潘的 Swift iOS App 開發問題解答集

彼得潘的iOS App程式設計入門,文組生的iOS App程式設計入門講師,彼得潘的 Swift 程式設計入門,App程式設計入門作者,http://apppeterpan.strikingly.com