iOS 工具 json 模型类生成
在开发过程中免不了要和后台交互,常用的数据格式是json,例如: 家谱图
{
"grandfather1": {
"father1": {
"son": {
"grandchild": {
"name": "tom",
"age": 18,
"smart": 1,
"have_girlfriend": 0
},
"name": "Jim",
"age": 40,
"haveBoy": 1,
"wife": "mei"
},
"name": "Dave",
"wife": "yun",
"have_son": 1,
"house": [
"house",
"house1",
"house2"
]
},
"father2": {
"son": {
"grandchild": {
"name": "tom",
"age": 18,
"smart": 1,
"have_girlfriend": 0
},
"name": "Jim",
"age": 40,
"haveBoy": 1,
"wife": "mei"
},
"name": "Dave",
"wife": "yun",
"have_son": 1,
"house": [
"house",
"house1",
"house2"
]
},
"name": "ton",
"retired": 1
},
"grandfather2": {
"father1": {
"son": {
"grandchild": {
"name": "tom",
"age": 18,
"smart": 1,
"have_girlfriend": 0
},
"name": "Jim",
"age": 40,
"haveBoy": 1,
"wife": "mei"
},
"name": "Dave",
"wife": "yun",
"have_son": 1,
"house": [
"house",
"house1",
"house2"
]
},
"father2": {
"son": {
"grandchild": {
"name": "tom",
"age": 18,
"smart": 1,
"have_girlfriend": 0
},
"name": "Jim",
"age": 40,
"haveBoy": 1,
"wife": "mei"
},
"name": "Dave",
"wife": "yun",
"have_son": 1,
"house": [
"house",
"house1",
"house2"
]
},
"name": "ton",
"retired": 1
}
}
这样的格式是很常见的,一般的都是一个字典对应一个模型,字典中的key,少一点还好,如果比较多的话,写起来可能就比较累了(毕竟这是一个体力活),所以我就偷懒,试着写了这么一个工具,帮助自己,节省体力(喝杯Java☕️的时间,就生成好模型),
具体用法是:
{
"grandfather1": {
"father1": {
"son": {
"grandchild": {
"name": "tom",
"age": 18,
"smart": 1,
"have_girlfriend": 0,
"class": "Grandchild"
},
"name": "Jim",
"age": 40,
"haveBoy": 1,
"wife": "mei",
"class": "Son"
},
"name": "Dave",
"wife": "yun",
"have_son": 1,
"house": [
"house",
"house1",
"house2"
],
"field": "value",
"class": "Father"
},
"father2": {
"son": {
"grandchild": {
"name": "tom",
"age": 18,
"smart": 1,
"have_girlfriend": 0
},
"name": "Jim",
"age": 40,
"haveBoy": 1,
"wife": "mei"
},
"name": "Dave",
"wife": "yun",
"have_son": 1,
"house": [
"house",
"house1",
"house2"
]
},
"name": "ton",
"retired": 1,
"class": "Grandfather"
},
"grandfather2": {
"father1": {
"son": {
"grandchild": {
"name": "tom",
"age": 18,
"smart": 1,
"have_girlfriend": 0
},
"name": "Jim",
"age": 40,
"haveBoy": 1,
"wife": "mei"
},
"name": "Dave",
"wife": "yun",
"have_son": 1,
"house": [
"house",
"house1",
"house2"
]
},
"father2": {
"son": {
"grandchild": {
"name": "tom",
"age": 18,
"smart": 1,
"have_girlfriend": 0
},
"name": "Jim",
"age": 40,
"haveBoy": 1,
"wife": "mei"
},
"name": "Dave",
"wife": "yun",
"have_son": 1,
"house": [
"house",
"house1",
"house2"
]
},
"name": "ton",
"retired": 1
}
}
在字典中添加了一个key:class(生成模型的文件名和类型名)
数字(0,1)表示bool类型,
这里有json文件(?)和model文件夹(生成类地址),
将json文件路径和model路径填写好(可以直接拖进去,一般人我都不告诉他),点击done,(喝杯Java☕️)然后,
就没有然后了,
GitHub : 点击打开链接