您的位置:首页 > 移动开发 > IOS开发

iOS 工具 json 模型类生成

2018-01-21 13:07 127 查看

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 : 点击打开链接
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iOS 模型 json