【问题标题】:How to read Ionic2 map object in ionic2? [duplicate]如何在 ionic2 中读取 Ionic2 映射对象? [复制]
【发布时间】:2017-03-20 19:27:20
【问题描述】:

我试图在ionic2 中获取一个具有键值的对象,我想在ionic2 中从中读取品牌名称

所以我的问题:

我如何从下面的对象中读取密钥

{
    "status": "success",
    "products": {
        "Key1": [
            {
              "entity_id": "448",
              "sku": "587",
              "name": "name",
              "image_url": "587.png",
              "price": "15,000",
              "qty": 0,
              "rating": 0,
              "wishlist": false,
              "specialprice": "7,500",
              "brand": "brandname"
            }
        ],
        "Key2": [
            {
              "entity_id": "448",
              "sku": "587",
              "name": "name",
              "image_url": "587.png",
              "price": "15,000",
              "qty": 0,
              "rating": 0,
              "wishlist": false,
              "specialprice": "7,500",
              "brand": "brandname"
            }
        ],
        "Key3": [
            {
              "entity_id": "448",
              "sku": "587",
              "name": "name",
              "image_url": "587.png",
              "price": "15,000",
              "qty": 0,
              "rating": 0,
              "wishlist": false,
              "specialprice": "7,500",
              "brand": "brandname"
            }
        ],
    }
}

请随时帮助我。

【问题讨论】:

    标签: json object angular ionic-framework ionic2


    【解决方案1】:

    如果您是包含此内容的变量,则称为data

    data.products 将返回产品列表。 (或“钥匙”在你的情况下。)

    然后调用data.products.Key1会给你Key1的对象。

    data.products.Key1.entity_id 将返回“448”。

    所以逻辑上你可以通过调用data.prodcuts.Key1.brand获得品牌名称

    编辑误读:

    由于您的Key1 出于某种原因是一个列表。

    data.products.Key1[0].brand

    【讨论】:

    猜你喜欢
    • 2016-12-09
    • 1970-01-01
    • 2017-08-29
    • 1970-01-01
    • 1970-01-01
    • 2017-06-07
    • 2019-03-18
    • 1970-01-01
    • 2017-05-12
    相关资源
    最近更新 更多