繁体   English   中英

如何在结构中定义字典列表

[英]How to define list of dictionaries in a struct

我想加载包含字典列表的 JSON,例如

{error: false, "objects": [{"id": 1, "name": "cat"}, {"id": 2, "name": "dog"}, {"id": 3, "name": "fish"}]

这怎么能定义在一个

struct name: Codable, Identifiable  {
}

在 JSONDecoder 中用于解码接收到的数据。
如何编写结构来定义此数据类型

struct data: Codable {
   let error: Bool
   let objects: [dataObjects]
}

struct dataObjects: Codable {
    let id: Int
    let name: String
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM