How to print Json response


#1

I want to print JSON response but when I try to print JSON response
below my json response but wheni tired to print this response on dropdown its printed like this Blue,Gray,Green,Red,Yellow but
I wnat to print like this
Blue
Gray
Green
Red
Yellow

[{"id":1,"name":"Color","position":0,"visible":true,"variation":true,
"options":["Blue","Gray","Green","Red","Yellow"]},{"id":2,"name":"Size","position":1,"visible":true,"variation":true,
"options":["Large","Medium","Small"]}]

Any help appriciated
Thanks


#2

You need to parse it. Try doing it in a loop and access the element field.


#3

Actually, I’m getting this value from navparams like this
this.attributes = JSON.parse(this.product.attribute)

		<div *ngFor="let item of attributes">
			{{item.options}}
		</div>

am try to do like this but did not get any solution


#4

html

<div *ngFor="let stat of six> {{stat.options}} </div> <p>ts file<br> six:any=[{“id”:1,“name”:“Color”,“position”:0,“visible”:true,“variation”:true,"options[“Blue”,“Gray”,“Green”,“Red”,“Yellow”]},{“id”:2,“name”:“Size”,“position”:1,“visible”:true,“variation”:true,<br> “options”:[“Large”,“Medium”,“Small”]}];</p> <p>just loop on the variable in which you store this json value you will get the result</p>

#5

You need nested ngFor

<div *ngFor="let item of attributes">
    <div *ngFor="let option of item.options">
        {{option}}
    </div>
</div>

This is what you need :wink:


#6

Also I have one problem dear. still am not able to print category

 getCategory(){
  	  	this.WooCommerce.getAsync("products/categories").then((data)=>{
  		console.log(JSON.parse(data.body))
                   this.category = JSON.parse(data.body)
  	},(error)=>{
  		console.log(error)

  	})
  }

this is my response

0: Object { id: 15, name: "Uncategorized", slug: "uncategorized", … }
​
1: Object { id: 30, name: "Shoes", slug: "shoes", … }

Please help me out