0

I am trying to fetch a object in ionic2 which has key value and i want to read the key and the brand name from it within ionic2.

so my question :

how i can read the key from the below object ?

{
    "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"
            }
        ],
    }
}

please feel free to help me.

0

1 Answer 1

0

If you're variable which contains this is called data.

data.products will return the list of products. (or 'Key's in your case.)

Then calling data.products.Key1 will give you the object of Key1.

data.products.Key1.entity_id will return '448'.

So logically you can get the brandname by calling data.prodcuts.Key1.brand

Edit misread:

Since your Key1 is a list for some reason.

data.products.Key1[0].brand

Sign up to request clarification or add additional context in comments.

2 Comments

thank you for your response but thekey1 and all other key i want to get dynamically any suggestion ?
Taken from github.com/paularmstrong/normalizr/issues/15 it says you can use for(let key of data.products) but I haven't tested myself

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.