【问题标题】:REST API: JSON objects in URL to get custom JSONREST API:URL 中的 JSON 对象以获取自定义 JSON
【发布时间】:2020-05-31 10:55:52
【问题描述】:

我正在使用 cs-cart rest API 创建一个安卓应用。我的问题是我想要根据需要的类别,例如父类别的 id 为“0”,所以我只想要那个类别,我可以编辑 URL 以仅获取其 parent_id:“0”的类别

http://www.example.com/api/categories

我也尝试过使用不同的在线工具进行 URL 编码,但都没有成功。

这是我现在得到的 JSON,我需要特定的 parent_id。

{
    "categories": [
        {
            "category_id": "735",
            "parent_id": "755",
            "id_path": "60/755/735",
            "category": "Clocks",
            "position": "0",
            "status": "A",
            "product_count": "1",
            "seo_name": "watches",
            "seo_path": "60/755"
        },
        {
            "category_id": "682",
            "parent_id": "295",
            "id_path": "217/295/682",
            "category": "360° Video Camera",
            "position": "0",
            "status": "A",
            "product_count": "514",
            "seo_name": "360-video-camera",
            "seo_path": "217/295"
        },
        {
            "category_id": "413",
            "parent_id": "0",
            "id_path": "413",
            "category": " Apparel",
            "position": "0",
            "status": "A",
            "product_count": "2",
            "seo_name": "apparel",
            "seo_path": ""
        },
        {
            "category_id": "359",
            "parent_id": "217",
            "id_path": "217/359",
            "category": "Computers ",
            "position": "0",
            "status": "A",
            "product_count": "25",
            "seo_name": "computer-cables",
            "seo_path": "217"
        },
        {
            "category_id": "357",
            "parent_id": "344",
            "id_path": "217/344/357",
            "category": "Chargers",
            "position": "0",
            "status": "A",
            "product_count": "1154",
            "seo_name": "network-media-converters",
            "seo_path": "217/344"
        },
        {
            "category_id": "355",
            "parent_id": "344",
            "id_path": "217/344/355",
            "category": "Cellphones",
            "position": "0",
            "status": "A",
            "product_count": "1469",
            "seo_name": "gateways-controllers",
            "seo_path": "217/344"
        },
        {
            "category_id": "345",
            "parent_id": "344",
            "id_path": "217/344/345",
            "category": "Bluetooth Accessories",
            "position": "0",
            "status": "A",
            "product_count": "1052",
            "seo_name": "network-antennas",
            "seo_path": "217/344"
        },
        {
            "category_id": "298",
            "parent_id": "295",
            "id_path": "217/295/298",
            "category": "Camera Accessories",
            "position": "0",
            "status": "A",
            "product_count": "507",
            "seo_name": "camera-accessories",
            "seo_path": "217/295"
        },
        {
            "category_id": "296",
            "parent_id": "295",
            "id_path": "217/295/296",
            "category": "Camcorders",
            "position": "0",
            "status": "A",
            "product_count": "504",
            "seo_name": "camcorders",
            "seo_path": "217/295"
        },
        {
            "category_id": "295",
            "parent_id": "217",
            "id_path": "217/295",
            "category": "Cameras & Camcorders",
            "position": "0",
            "status": "A",
            "product_count": "0",
            "seo_name": "cameras-and-camcorders",
            "seo_path": "217"
        },
        {
            "category_id": "271",
            "parent_id": "218",
            "id_path": "217/218/271",
            "category": "Audio Amplifiers",
            "position": "0",
            "status": "A",
            "product_count": "1003",
            "seo_name": "audio-amplifiers",
            "seo_path": "217/218"
        },
        {
            "category_id": "238",
            "parent_id": "218",
            "id_path": "217/218/238",
            "category": "Bluetooth Music Receivers",
            "position": "0",
            "status": "A",
            "product_count": "519",
            "seo_name": "bluetooth-music-receivers",
            "seo_path": "217/218"
        },
        {
            "category_id": "218",
            "parent_id": "217",
            "id_path": "217/218",
            "category": "Audio & Home Theatre",
            "position": "0",
            "status": "A",
            "product_count": "1",
            "seo_name": "audio-and-home-theatre",
            "seo_path": "217"
        },
        {
            "category_id": "188",
            "parent_id": "779",
            "id_path": "776/779/188",
            "category": "Baby Furniture",
            "position": "0",
            "status": "A",
            "product_count": "430",
            "seo_name": "baby-furniture",
            "seo_path": "776/779"
        },
        {
            "category_id": "185",
            "parent_id": "779",
            "id_path": "776/779/185",
            "category": "Baby Travel",
            "position": "0",
            "status": "A",
            "product_count": "494",
            "seo_name": "baby-travel",
            "seo_path": "776/779"
        },
        {
            "category_id": "169",
            "parent_id": "779",
            "id_path": "776/779/169",
            "category": "Baby Bathing & Potting",
            "position": "0",
            "status": "A",
            "product_count": "405",
            "seo_name": "baby-bathing-and-potting",
            "seo_path": "776/779"
        },
        {
            "category_id": "109",
            "parent_id": "108",
            "id_path": "101/108/109",
            "category": "BD/DVD Movies",
            "position": "0",
            "status": "A",
            "product_count": "0",
            "seo_name": "bd-dvd-movies",
            "seo_path": "101/108"
        },
        {
            "category_id": "90",
            "parent_id": "85",
            "id_path": "60/85/90",
            "category": "Cups & Mugs",
            "position": "0",
            "status": "A",
            "product_count": "504",
            "seo_name": "cups-and-mugs",
            "seo_path": "60/85"
        },
        {
            "category_id": "83",
            "parent_id": "69",
            "id_path": "60/69/83",
            "category": "Ceiling Lights",
            "position": "0",
            "status": "A",
            "product_count": "592",
            "seo_name": "ceiling-lighting",
            "seo_path": "60/69"
        },
        {
            "category_id": "70",
            "parent_id": "69",
            "id_path": "60/69/70",
            "category": " Bulbs & Tubes ",
            "position": "0",
            "status": "A",
            "product_count": "504",
            "seo_name": "bulbs",
            "seo_path": "60/69"
        }
    ],
    "params": {
        "category_id": 0,
        "visible": false,
        "current_category_id": 0,
        "simple": false,
        "plain": true,
        "limit": 0,
        "item_ids": "",
        "group_by_level": false,
        "get_images": false,
        "category_delimiter": "/",
        "get_frontend_urls": false,
        "max_nesting_level": null,
        "get_company_name": false,
        "items_per_page": 20,
        "page": 1,
        "except_id": 414,
        "sort_order": "asc",
        "sort_by": "position",
        "sort_order_rev": "desc",
        "total_items": "557"
    }
}

【问题讨论】:

  • 好吧!!这取决于服务器端是否允许您按父 ID 过滤类别。否则,您需要遍历所有结果并对其进行过滤。
  • 500多个品类,上百万种产品,如何配置?这会降低应用速度

标签: java json url cs-cart


【解决方案1】:

如果您只想在 API 调用中获取 parent_id 为 0 的类别,请使用 URL:

http://www.example.com/api/categories?category_id=0&visible=true

当然,可以使用任何其他 id 来代替 0,只要确保添加 &visible=true 参数即可。

【讨论】:

  • 兄弟,你太棒了。好吧,这里可见的参数显示了什么,还有一个问题,为什么我们使用 category_id=0,而不是 parent_id=0?
  • 这就像您正在获取有关 ID 为 0 的类别的信息。碰巧 API 可以为您提供有关某个类别的唯一信息实际上是其子类别的列表,所以如果一些其他数据可用,它会被放在“类别”的兄弟节点。
  • visible=true 在我看来也不是很合理,但事实就是如此。来源:我自己检查了实现
  • 感谢您的帮助,非常有帮助。
猜你喜欢
  • 1970-01-01
  • 2011-09-28
  • 2015-12-23
  • 2020-05-16
  • 1970-01-01
  • 2014-07-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多