如何在ios中存储类别等数据
Posted
技术标签:
【中文标题】如何在ios中存储类别等数据【英文标题】:How to store the data like category in ios 【发布时间】:2015-04-25 15:02:10 【问题描述】:我正在使用一个购物应用程序,并且我有响应数据,例如示例的所有类别主类别有男性、女性、儿童等。每个都有子类别,如 T 恤、衬衫、鞋类等,还有一些子类(例如鞋类)休闲鞋、正装鞋、凉鞋等 那么如何存储此响应以及如何显示一个特定类别?
这是我的回应
"success":true,
"category":[
"category_id":"74",
"parent_id":"0",
"name":"Grocery",
"image":"catalog\/Rice.jpg",
"top":"1",
"column":"1",
"sort_order":"0",
"status":"1",
"date_added":"2015-03-25 11:26:46",
"date_modified":"2015-04-20 11:04:29",
"description":"<p><br><\/p>",
"meta_title":"Grocery",
"meta_description":"",
"meta_keyword":"",
"store_id":"0",
"subcategory":[
"category_id":"75",
"parent_id":"74",
"name":"Dals & Pulses",
"image":"catalog\/0004620_dm-gram-dal-1kg.png",
"top":"0",
"column":"0",
"sort_order":"1",
"status":"1",
"date_added":"2015-03-25 11:42:20",
"date_modified":"2015-04-20 11:08:24",
"description":"<p><br><\/p>",
"meta_title":"Dals & Pulses",
"meta_description":"",
"meta_keyword":"",
"store_id":"0"
,
"category_id":"76",
"parent_id":"74",
"name":"Dry Fruits & Nuts",
"image":"catalog\/almonds.jpg",
"top":"0",
"column":"0",
"sort_order":"2",
"status":"1",
"date_added":"2015-03-25 12:17:39",
"date_modified":"2015-04-20 11:08:11",
"description":"<p><br><\/p>",
"meta_title":"Dry Fruits & Nuts",
"meta_description":"",
"meta_keyword":"",
"store_id":"0"
,
"category_id":"77",
"parent_id":"74",
"name":"Edible Oil & Ghees",
"image":"catalog\/oil.jpg",
"top":"0",
"column":"0",
"sort_order":"3",
"status":"1",
"date_added":"2015-03-25 15:06:06",
"date_modified":"2015-04-16 18:03:13",
"description":"<p><br><\/p>",
"meta_title":"Edible Oil & Ghees",
"meta_description":"",
"meta_keyword":"",
"store_id":"0"
,
"category_id":"78",
"parent_id":"74",
"name":"Atta & Flour",
"image":"catalog\/aashirvaad-atta-whole-wheat-noworry.jpg",
"top":"0",
"column":"0",
"sort_order":"5",
"status":"1",
"date_added":"2015-03-25 16:27:52",
"date_modified":"2015-04-20 11:04:38",
"description":"<p><br><\/p>",
"meta_title":"Atta & Flour",
"meta_description":"",
"meta_keyword":"",
"store_id":"0"
,
"category_id":"79",
"parent_id":"74",
"name":"Rice",
"image":"catalog\/Rice.jpg",
"top":"0",
"column":"0",
"sort_order":"6",
"status":"1",
"date_added":"2015-03-25 16:42:55",
"date_modified":"2015-04-16 18:03:40",
"description":"<p><br><\/p>",
"meta_title":"Rice",
"meta_description":"",
"meta_keyword":"",
"store_id":"0"
,
"category_id":"80",
"parent_id":"74",
"name":"Salt & Sugar",
"image":"catalog\/Sugar.jpg",
"top":"0",
"column":"0",
"sort_order":"7",
"status":"1",
"date_added":"2015-03-25 16:53:12",
"date_modified":"2015-03-25 20:10:24",
"description":"<p><br><\/p>",
"meta_title":"Salt & Sugar",
"meta_description":"",
"meta_keyword":"",
"store_id":"0"
,
"category_id":"81",
"parent_id":"74",
"name":"Millets",
"image":"catalog\/Millets.JPG",
"top":"0",
"column":"0",
"sort_order":"8",
"status":"1",
"date_added":"2015-03-25 17:02:57",
"date_modified":"2015-04-16 18:04:09",
"description":"<p><br><\/p>",
"meta_title":"Millets",
"meta_description":"",
"meta_keyword":"",
"store_id":"0"
]
,
"category_id":"82",
"parent_id":"0",
"name":"chips",
"image":null,
"top":"1",
"column":"1",
"sort_order":"2",
"status":"1",
"date_added":"2015-03-27 18:31:51",
"date_modified":"2015-04-24 00:01:47",
"description":"<p>chips are crispy<\/p>",
"meta_title":"chips",
"meta_description":"",
"meta_keyword":"",
"store_id":"0",
"subcategory":[
"category_id":"83",
"parent_id":"82",
"name":"lays",
"image":"catalog\/cashew4.jpg",
"top":"0",
"column":"0",
"sort_order":"1",
"status":"1",
"date_added":"2015-03-27 18:32:53",
"date_modified":"2015-04-23 23:45:59",
"description":"<p>lays<\/p>",
"meta_title":"lays",
"meta_description":"",
"meta_keyword":"",
"store_id":"0"
]
,
"category_id":"84",
"parent_id":"0",
"name":"Food Items",
"image":"catalog\/slide.jpg",
"top":"1",
"column":"1",
"sort_order":"3",
"status":"1",
"date_added":"2015-04-26 22:13:21",
"date_modified":"2015-04-26 22:13:21",
"description":"Food Items",
"meta_title":"Food Items",
"meta_description":"",
"meta_keyword":"",
"store_id":"0",
"subcategory":"null"
,
"category_id":"86",
"parent_id":"0",
"name":"HouseHold",
"image":"catalog\/aashirvaad-atta-whole-wheat-noworry.jpg",
"top":"1",
"column":"1",
"sort_order":"5",
"status":"1",
"date_added":"2015-04-26 22:36:03",
"date_modified":"2015-04-26 22:40:46",
"description":"HouseHold",
"meta_title":"HouseHold",
"meta_description":"",
"meta_keyword":"",
"store_id":"0",
"subcategory":"null"
,
"category_id":"85",
"parent_id":"0",
"name":"Bread & Diary",
"image":"catalog\/orid dhal 500gm.JPG",
"top":"1",
"column":"1",
"sort_order":"6",
"status":"1",
"date_added":"2015-04-26 22:30:14",
"date_modified":"2015-04-26 22:40:17",
"description":"Bread &amp; Diary",
"meta_title":"Bread & Diary",
"meta_description":"",
"meta_keyword":"",
"store_id":"0",
"subcategory":"null"
,
"category_id":"87",
"parent_id":"0",
"name":"Fruits & Vegetables",
"image":"catalog\/cashew4.jpg",
"top":"1",
"column":"1",
"sort_order":"7",
"status":"1",
"date_added":"2015-04-26 22:41:52",
"date_modified":"2015-04-26 22:41:52",
"description":"Fruits &amp; Vegetables",
"meta_title":"Fruits & Vegetables",
"meta_description":"",
"meta_keyword":"",
"store_id":"0",
"subcategory":"null"
]
【问题讨论】:
你想将数据存储在本地变量还是本地数据库,即sqlite?你到底想要怎么样?如果可能,请向我们展示示例响应数据 存储在局部变量中,然后我更新响应 【参考方案1】:您可以在此类中创建类“衣服”,您将拥有诸如“类别”、“子类别”、“标题”、“图像”之类的属性。对于“类别”,您可以使用 typedef 枚举。如果你想保存对象使用 CoreData,创建一个具有相似属性的实体并保存你的数据。
【讨论】:
以上是关于如何在ios中存储类别等数据的主要内容,如果未能解决你的问题,请参考以下文章
如何在 iOS 应用程序中存储机密、密钥、令牌、加密密钥等关键敏感信息
如何在 Push Sharp 库中的 APNS 有效负载中添加类别以进行交互式通知 ios