1

在我的 WooCommerce android 应用程序中,当我从 URL 获取时,我得到了类别响应mysite/wc-api/v3/products/categories。我的要求是我需要以不同的方式获取类别和子类别。在我的回复中,我将类别和子类别放在一起。

响应中有什么方法或关键可以区分两者吗?

以下是我的回复:

{
    "product_categories": [{
        "id": 2016,
        "name": "Accessories",
        "slug": "accessories",
        "parent": 0,
        "description": "",
        "display": "default",
        "image": "https:\/\/s3.amazonaws.com\/appilywebstie\/uploads\/2016\/09\/09111142\/Salona-Bichona-Cotton-Kitchen-Apron-Set-1896-6241932-2-zoom.jpg",
        "count": 1
    }, {
        "id": 2055,
        "name": "Anklets",
        "slug": "anklets",
        "parent": 2016,
        "description": "",
        "display": "subcategories",
        "image": "",
        "count": 2
    }, {
        "id": 2014,
        "name": "Bags",
        "slug": "bags",
        "parent": 0,
        "description": "",
        "display": "default",
        "image": "https:\/\/s3.amazonaws.com\/appilywebstie\/uploads\/2016\/09\/15045015\/dicount.jpg",
        "count": 0
    }, {
        "id": 2052,
        "name": "Bangles",
        "slug": "bangles",
        "parent": 2015,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2068,
        "name": "Bath and Body",
        "slug": "bath-and-body",
        "parent": 2017,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2017,
        "name": "Beauty",
        "slug": "beauty",
        "parent": 0,
        "description": "",
        "display": "default",
        "image": "https:\/\/s3.amazonaws.com\/appilywebstie\/uploads\/2016\/09\/01105455\/sexy-hd-hot-girls-wallpaper.jpg",
        "count": 0
    }, {
        "id": 2058,
        "name": "Belts",
        "slug": "belts",
        "parent": 2016,
        "description": "",
        "display": "subcategories",
        "image": "",
        "count": 1
    }, {
        "id": 2040,
        "name": "Boots",
        "slug": "boots",
        "parent": 2013,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2023,
        "name": "Bottomwear",
        "slug": "bottomwear",
        "parent": 2010,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2035,
        "name": "Bottomwear",
        "slug": "bottomwear-westernwear",
        "parent": 2012,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2071,
        "name": "Bra and Panty Set",
        "slug": "bra-and-panty-set",
        "parent": 2018,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2069,
        "name": "Bras",
        "slug": "bras",
        "parent": 2018,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2086,
        "name": "Camisoles",
        "slug": "camisoles",
        "parent": 2018,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2044,
        "name": "Clutches",
        "slug": "clutches",
        "parent": 2014,
        "description": "",
        "display": "default",
        "image": "",
        "count": 20
    }, {
        "id": 2028,
        "name": "Dresses",
        "slug": "dresses",
        "parent": 2012,
        "description": "",
        "display": "default",
        "image": "",
        "count": 26
    }, {
        "id": 2048,
        "name": "Earrings",
        "slug": "earrings",
        "parent": 2015,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2010,
        "name": "Ethnic",
        "slug": "ethnic",
        "parent": 0,
        "description": "",
        "display": "default",
        "image": "https:\/\/s3.amazonaws.com\/appilywebstie\/uploads\/2016\/09\/15054330\/Ethnic.jpg",
        "count": 3
    }, {
        "id": 2064,
        "name": "Eyes",
        "slug": "eyes",
        "parent": 2017,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2065,
        "name": "Face",
        "slug": "face",
        "parent": 2017,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2038,
        "name": "Flats",
        "slug": "flats",
        "parent": 2013,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2039,
        "name": "Flip Flops",
        "slug": "flip-flops",
        "parent": 2013,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2062,
        "name": "Hair Accessories",
        "slug": "hair-accessories",
        "parent": 2016,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2067,
        "name": "Haircare",
        "slug": "haircare",
        "parent": 2017,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2047,
        "name": "Handbags",
        "slug": "handbags",
        "parent": 2014,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2043,
        "name": "Heels",
        "slug": "heels",
        "parent": 2013,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2033,
        "name": "Jeans",
        "slug": "jeans",
        "parent": 2012,
        "description": "",
        "display": "default",
        "image": "",
        "count": 1
    }, {
        "id": 2015,
        "name": "Jewellery",
        "slug": "jewellery",
        "parent": 0,
        "description": "",
        "display": "default",
        "image": "https:\/\/s3.amazonaws.com\/appilywebstie\/uploads\/2016\/09\/09105848\/Moedbuille-Blue-Alloy-Danglers-26-Drop-8028-7838022-1-zoom.jpg",
        "count": 0
    }, {
        "id": 2056,
        "name": "Jewellery Sets",
        "slug": "jewellery-sets",
        "parent": 2015,
        "description": "",
        "display": "default",
        "image": "",
        "count": 2
    }, {
        "id": 2029,
        "name": "Jumpsuits",
        "slug": "jumpsuits",
        "parent": 2012,
        "description": "",
        "display": "default",
        "image": "",
        "count": 4
    }, {
        "id": 2019,
        "name": "Kurtis",
        "slug": "kurtis",
        "parent": 2010,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2022,
        "name": "Lehengas",
        "slug": "lehengas",
        "parent": 2010,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2018,
        "name": "Lingerie",
        "slug": "lingerie",
        "parent": 0,
        "description": "",
        "display": "default",
        "image": "https:\/\/s3.amazonaws.com\/appilywebstie\/uploads\/2016\/09\/06072036\/881382626889.jpg",
        "count": 0
    }, {
        "id": 2063,
        "name": "Lips",
        "slug": "lips",
        "parent": 2017,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2054,
        "name": "Maangtika",
        "slug": "maangtika",
        "parent": 2015,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2066,
        "name": "Nails",
        "slug": "nails",
        "parent": 2017,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2051,
        "name": "Necklaces",
        "slug": "necklaces",
        "parent": 2015,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2072,
        "name": "Nightwear",
        "slug": "nightwear",
        "parent": 2018,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2053,
        "name": "Noserings",
        "slug": "noserings",
        "parent": 2015,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2057,
        "name": "Offbeat Jewellery",
        "slug": "offbeat-jewellery",
        "parent": 2015,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2070,
        "name": "Panties",
        "slug": "panties",
        "parent": 2018,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2034,
        "name": "Pants",
        "slug": "pants",
        "parent": 2012,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2049,
        "name": "Pendants",
        "slug": "pendants",
        "parent": 2015,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2050,
        "name": "Rings",
        "slug": "rings",
        "parent": 2015,
        "description": "",
        "display": "default",
        "image": "",
        "count": 3
    }, {
        "id": 2036,
        "name": "Sandal",
        "slug": "sandal",
        "parent": 2013,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2020,
        "name": "Sarees",
        "slug": "sarees",
        "parent": 2010,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2059,
        "name": "Scarves",
        "slug": "scarves",
        "parent": 2016,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2025,
        "name": "Shirts",
        "slug": "shirts",
        "parent": 2011,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2013,
        "name": "Shoes",
        "slug": "shoes",
        "parent": 0,
        "description": "",
        "display": "default",
        "image": "https:\/\/s3.amazonaws.com\/appilywebstie\/uploads\/2016\/09\/01111200\/Black1460634399.jpg",
        "count": 0
    }, {
        "id": 2032,
        "name": "Shorts",
        "slug": "shorts",
        "parent": 2012,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2031,
        "name": "Skirts",
        "slug": "skirts",
        "parent": 2012,
        "description": "",
        "display": "default",
        "image": "",
        "count": 12
    }, {
        "id": 2085,
        "name": "Sleepwear",
        "slug": "sleepwear",
        "parent": 2018,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2045,
        "name": "Sling Bags",
        "slug": "sling-bags",
        "parent": 2014,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2037,
        "name": "Slip Ons",
        "slug": "slip-ons",
        "parent": 2013,
        "description": "",
        "display": "default",
        "image": "",
        "count": 4
    }, {
        "id": 2041,
        "name": "Sneakers",
        "slug": "sneakers",
        "parent": 2013,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2021,
        "name": "Suits",
        "slug": "suits",
        "parent": 2010,
        "description": "",
        "display": "default",
        "image": "",
        "count": 31
    }, {
        "id": 2060,
        "name": "Sunglasses",
        "slug": "sunglasses",
        "parent": 2016,
        "description": "",
        "display": "subcategories",
        "image": "",
        "count": 5
    }, {
        "id": 2024,
        "name": "T Shirts",
        "slug": "t-shirts",
        "parent": 2011,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2011,
        "name": "Tops",
        "slug": "tops",
        "parent": 0,
        "description": "",
        "display": "default",
        "image": "https:\/\/s3.amazonaws.com\/appilywebstie\/uploads\/2016\/09\/15055420\/TOPS.jpg",
        "count": 0
    }, {
        "id": 2026,
        "name": "Tops",
        "slug": "tops-tops",
        "parent": 2011,
        "description": "",
        "display": "default",
        "image": "",
        "count": 10
    }, {
        "id": 2027,
        "name": "Tunics",
        "slug": "tunics",
        "parent": 2011,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2046,
        "name": "Wallets",
        "slug": "wallets",
        "parent": 2014,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2061,
        "name": "Watches",
        "slug": "watches",
        "parent": 2016,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2042,
        "name": "Wedges",
        "slug": "wedges",
        "parent": 2013,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2030,
        "name": "Western Suits",
        "slug": "western-suits",
        "parent": 2012,
        "description": "",
        "display": "default",
        "image": "",
        "count": 0
    }, {
        "id": 2012,
        "name": "WesternWear",
        "slug": "westernwear",
        "parent": 0,
        "description": "",
        "display": "default",
        "image": "https:\/\/s3.amazonaws.com\/appilywebstie\/uploads\/2016\/09\/15054714\/BRANDS.jpg",
        "count": 9
    }]
}
4

2 回答 2

3

类别和子类别的区别在于"parent"属性:

  • 类别:(总是值)"parent": 0 0
  • 子类别"parent"==>始终具有id其父类别的

我希望这就是您正在查看的内容,因为当您查看数据时很明显。

于 2016-10-03T07:39:59.760 回答
1

最后我得到了答案,所有的子类别都用 key 映射到它们的父类别parent。类别的键parent0,子类别的键parentparent category key

于 2016-10-03T07:34:14.697 回答