如何在ios中保存和检索JSON响应

时间:2015-04-30 09:49:44

标签: ios json jsonresponse

我正在使用一个购物应用程序,我有响应数据,如所有类别。我的回答我解析了主类别名称和子类别分开,但我想存储和检索下面的子类别主要类别如下。
这是First Category Grocery,子类别是Dals& amp;加号,干果和坚果......喜欢这个我想要保存所有类别和他们的子类别。我想通过主类别显示子类别给我一些想法,帮助我请...

Grocery 
(
    "Dals & Pulses",
    "Dry Fruits & Nuts",
    "Edible Oil & Ghees",
    "Atta & Flour",
    Rice,
    "Salt & Sugar",
    Millets)
Chips(
    Lays,
    Kurkure,
    "Potato Chips",
    Bingo,
    "Haldiram's",
    "Corn Chips"
)
Food Items(
    "Baking & Gulab Jamun Mix",
    "Breakfast Cereals",
    Chocolates,
    Noodles,
    "Health & Nutrition",
    "Sauces & Ketchup"
)

这是我的回答:

{  
   "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 & 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 & Vegetables",
         "meta_title":"Fruits & Vegetables",
         "meta_description":"",
         "meta_keyword":"",
         "store_id":"0",
         "subcategory":"null"
      }
   ]
}

1 个答案:

答案 0 :(得分:1)

设计并制作包含类别和子类别的模型类。

然后将您的json响应数据解析为模型类。

这是数据结构问题。