我希望用json文件中的数据填充各种集合视图和表视图。但是,我不知道如何编写JSON文件。
这是我想要填充的数据:
- 2个扇区:";数据";以及";开发者">
- 每个扇区包含多个项目:
对于";数据":
- "数据科学家">
- "商业智能分析员(BIA(">
- "数据库开发人员">
- "数据库管理员">
- "数据工程师">
- "Data Analytics Manager">
- "数据安全管理员">
对于";显影剂":
- "APL">
- "BASIC">
- "Eiffel">
- "Frink">
- "Lisp">
- "Pascal">
- "Python">
- "Ruby">
- "S-Lang">
我需要如何组织数据以便以后检索它们?
要将JSON翻译成部分,我建议使用数组
[
{"title":"data",
"items":["Data Scientist","Business Intelligence Analyst (BIA)","Database Developer","Database Administrator","Data Engineer","Data Analytics Manager","Data Security Administrator"]
},
{"title":"developer",
"items":["APL","BASIC","Eiffel","Frink","Lisp","Pascal","Python","Ruby","S-Lang"]
}
]
并将其解码为
struct Section : Decodable {
let title : String
let items : [String]
}
它是最适合表/集合视图数据源的结构
JSON是一种非常稳定的正向格式-字符串用双引号表示,数组用方括号表示,字典用花括号表示:
{
"data" : [
"Data Scientist",
"Business Intelligence Analyst (BIA)",
"Database Developer",
"Database Administrator",
"Data Engineer",
"Data Analytics Manager",
"Data Security Administrator"
],
"developer": [
"APL",
"BASIC",
"Eiffel",
"Frink",
"Lisp",
"Pascal",
"Python",
"Ruby",
"S-Lang"
]
}