Hi all,
I have some JSON data (Woocommerce product data from rest api) which is multiple “layers” deep with sub, sub arrays and such.
I can access the initial dictionary in the main array but I am having trouble getting the data from arrays within that first layer of dictionary’s.
I want to add the data to a local database and I can do that with the main section, the first level data such as ID, Name etc as I have tried the classic framework methods from the examples and the new Framework examples and I can extract the main top layer (Id, Name, slug ect) but I can’t seem to get to the sub arrays such as related ids, categories, tags etc as they are either presented as Objects (which I can’t convert to arrays - don’t know how) which are also sometimes empty or I can’t get to the child nodes in the Json data.
I have been at it for so long that I have lost track of what I did at the beginning and I will be rewriting it from scratch!
Any pointers, hints tips would be appreciated.
an example from my testing website:
[{
"id": 35,
"name": "A DooDah (Copy) (Copy)",
"slug": "a-doodah-copy-copy",
"permalink": "https://www.greendealbromley.co.uk/product/a-doodah-copy-copy/",
"date_created": "2016-07-27T08:55:51",
"date_modified": "2016-07-27T13:56:44",
"type": "simple",
"status": "publish",
"featured": false,
"catalog_visibility": "visible",
"description": "<p>This is a widget text</p>\
",
"short_description": "",
"sku": "",
"price": "29.54",
"regular_price": "29.54",
"sale_price": "",
"date_on_sale_from": "",
"date_on_sale_to": "",
"price_html": "<span class=\"woocommerce-Price-amount amount\"><span class=\"woocommerce-Price-currencySymbol\">£</span>29.54</span>",
"on_sale": false,
"purchasable": true,
"total_sales": 0,
"virtual": false,
"downloadable": false,
"downloads": [],
"download_limit": -1,
"download_expiry": -1,
"download_type": "standard",
"external_url": "",
"button_text": "",
"tax_status": "taxable",
"tax_class": "",
"manage_stock": true,
"stock_quantity": 2,
"in_stock": true,
"backorders": "no",
"backorders_allowed": false,
"backordered": false,
"sold_individually": false,
"weight": "",
"dimensions": {
"length": "1",
"width": "2",
"height": "3"
},
"shipping_required": true,
"shipping_taxable": true,
"shipping_class": "",
"shipping_class_id": 0,
"reviews_allowed": true,
"average_rating": "0.00",
"rating_count": 0,
"related_ids": [16, 17, 9, 22, 21],
"upsell_ids": [],
"cross_sell_ids": [],
"parent_id": 0,
"purchase_note": "",
"categories": [{
"id": 9,
"name": "Bits",
"slug": "bits"
}],
"tags": [{
"id": 7,
"name": "Bits and Bobs",
"slug": "bits-and-bobs"
}],
"images": [{
"id": 10,
"date_created": "2016-04-21T16:31:43",
"date_modified": "2016-04-21T16:31:43",
"src": "https://www.greendealbromley.co.uk/wp-content/uploads/2016/04/Aquabion.jpg",
"name": "Aquabion",
"alt": "",
"position": 0
}],
"attributes": [],
"default_attributes": [],
"variations": [],
"grouped_products": [],
"menu_order": 0,
"_links": {
"self": [{
"href": "https://www.greendealbromley.co.uk/wp-json/wc/v1/products/35"
}],
"collection": [{
"href": "https://www.greendealbromley.co.uk/wp-json/wc/v1/products"
}]
}
}, {
"id": 34,
"name": "My Widget (Copy) (Copy)",
"slug": "my-widget-copy-copy",
"permalink": "https://www.greendealbromley.co.uk/product/my-widget-copy-copy/",
"date_created": "2016-07-27T08:55:45",
"date_modified": "2016-07-27T08:55:47",
"type": "simple",
"status": "publish",
"featured": false,
"catalog_visibility": "visible",
"description": "<p>This is a widget text</p>\
",
"short_description": "",
"sku": "",
"price": "29.54",
"regular_price": "29.54",
"sale_price": "",
"date_on_sale_from": "",
"date_on_sale_to": "",
"price_html": "<span class=\"woocommerce-Price-amount amount\"><span class=\"woocommerce-Price-currencySymbol\">£</span>29.54</span>",
"on_sale": false,
"purchasable": true,
"total_sales": 0,
"virtual": false,
"downloadable": false,
"downloads": [],
"download_limit": -1,
"download_expiry": -1,
"download_type": "standard",
"external_url": "",
"button_text": "",
"tax_status": "taxable",
"tax_class": "",
"manage_stock": true,
"stock_quantity": 2,
"in_stock": true,
"backorders": "no",
"backorders_allowed": false,
"backordered": false,
"sold_individually": false,
"weight": "",
"dimensions": {
"length": "",
"width": "",
"height": ""
},
"shipping_required": true,
"shipping_taxable": true,
"shipping_class": "",
"shipping_class_id": 0,
"reviews_allowed": true,
"average_rating": "0.00",
"rating_count": 0,
"related_ids": [13, 16, 15, 19, 23],
"upsell_ids": [],
"cross_sell_ids": [],
"parent_id": 0,
"purchase_note": "",
"categories": [{
"id": 6,
"name": "Things",
"slug": "things"
}],
"tags": [{
"id": 7,
"name": "Bits and Bobs",
"slug": "bits-and-bobs"
}],
"images": [{
"id": 10,
"date_created": "2016-04-21T16:31:43",
"date_modified": "2016-04-21T16:31:43",
"src": "https://www.greendealbromley.co.uk/wp-content/uploads/2016/04/Aquabion.jpg",
"name": "Aquabion",
"alt": "",
"position": 0
}],
"attributes": [],
"default_attributes": [],
"variations": [],
"grouped_products": [],
"menu_order": 0,
"_links": {
"self": [{
"href": "https://www.greendealbromley.co.uk/wp-json/wc/v1/products/34"
}],
"collection": [{
"href": "https://www.greendealbromley.co.uk/wp-json/wc/v1/products"
}]
}
}]