jeudi 31 mars 2016

Inserting an API data to the SQliteDatabase

I have an JSON API of Catelog Website. I am fetching the data with AsyncTask and inserting it to the sqlitedb. I made two tables in my db 1. category 2.products I fetched all the data separately for both table. Now I want to display category table data to gridView of mainActivity and onItemClick this will go to the class productList. for this productList class, should be display a listview of the product array data for the clicked item. One more query is when I close the app and reOpen the app, the data is again fetched and inserted into db. How to remove Data duplication.

My JSON Data is like:

[
{
id: 12,
name: "Electronices",
slug: "electronic",
description: "All Kind Of Electronic Devices",
parent_id: 0,
lft: null,
rgt: null,
depth: null,
created_at: "2016-03-07 13:14:23",
updated_at: "2016-03-07 13:14:23",
products: [
{
id: 14,
name: "samsung fame 2",
slug: "samsung_fame_2",
short_description: "",
has_offer: 0,
has_prescription: 0,
offer_description: "",
description: "",
price: "8000.00",
old_price: null,
shipping: null,
status: "",
stock_status: "",
weight: "",
meta_title: "",
meta_keywords: "",
meta_description: "",
created_at: "2016-03-07 13:27:06",
updated_at: "2016-03-07 13:27:06",
pivot: {
categorie_id: 12,
product_id: 14
},
photos: [
{
id: 14,
product_id: 14,
cover: 0,
image: "images/products/14/download.jpg",
label: "download.jpg",
sort_order: 1,
created_at: "2016-03-07 13:27:10",
updated_at: "2016-03-07 13:27:10"
},
{
id: 15,
product_id: 14,
cover: 0,
image: "images/products/14/chair.jpg",
label: "chair.jpg",
sort_order: 2,
created_at: "2016-03-07 13:27:20",
updated_at: "2016-03-07 13:27:20"
}
]
},
{
id: 16,
name: "Television sets",
slug: "Tv",
short_description: "",
has_offer: 0,
has_prescription: 0,
offer_description: "",
description: "",
price: "15000.00",
old_price: null,
shipping: null,
status: "",
stock_status: "",
weight: "",
meta_title: "",
meta_keywords: "",
meta_description: "",
created_at: "2016-03-07 13:27:56",
updated_at: "2016-03-07 13:27:56",
pivot: {
categorie_id: 12,
product_id: 16
},
photos: [
{
id: 18,
product_id: 16,
cover: 0,
image: "images/products/16/tv.jpg",
label: "tv.jpg",
sort_order: 2,
created_at: "2016-03-07 13:28:07",
updated_at: "2016-03-07 13:28:07"
}
]
}
]
},
{
  "Data for Furniture, like aboove"
}
]

Aucun commentaire:

Enregistrer un commentaire