JSONDecoder & Codable, Always Returning nil

參考網址
在這裏插入圖片描述

 do {
         let datajsonObject =  try jsonDecode.decode([Int64:EBORecognizedObject].self, from: datastr!)
        debugPrint("datajsonObject ==\(datajsonObject)")
    } catch  {
        debugPrint(error)
    }
  • 需要注意的地方是 T.Type 的類型 必須要一致
    Int 和 Int64 需要明確定義 不然得到的結果還是爲nil

  • 字典或者數組中存儲的對象包 遵守了Codable 協議
    那麼 這個字典或者數組也默認實現了Codable協議

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章