我需要显示数组数组数据。
我的API响应:
{
"product_id": "13",
"is_master": "0",
"sku": "Variable_product_15",
"upc": "",
"price": "40.00000",
"pricing_calculator": "standard",
"shipping": "0",
"params": "{\"variant_main_image\":\"images\\/themeparrot\\/clothing_products_06.png\"}",
"length": "0.00000",
"width": "0.00000",
"height": "0.00000",
}
在此数组中,我需要显示variant_main_image
。
我的 ts :
variableprod() {
let j2s = this.vproductsj2sid.find(x => x.j2store_variant_id === this.vprodid);
console.log("show"+JSON.stringify(j2s));
this.vcategorydata =JSON.parse(JSON.stringify(j2s.price));
console.log(JSON.stringify("vname: "+JSON.stringify(this.vcategorydata)));
this.vpdimages = JSON.parse(JSON.stringify(j2s.params));
this.vimg = this.vpdimages.variant_main_image;
console.log(JSON.stringify("vimg: "+JSON.stringify(this.vimg)));
}
在日志中,它仅显示 "vimg: undefined"
答案 0 :(得分:0)
this.vpdimages = JSON.parse(j2s.params);
仅在中使用JSON.parse()
this.vpdimages = JSON.parse(JSON.stringify(j2s.params));
答案 1 :(得分:0)
尝试
let apiRespose = {
"product_id": "13",
"is_master": "0",
"sku": "Variable_product_15",
"upc": "",
"price": "40.00000",
"pricing_calculator": "standard",
"shipping": "0",
"params": "{\"variant_main_image\":\"images\\/themeparrot\\/clothing_products_06.png\"}",
"length": "0.00000",
"width": "0.00000",
"height": "0.00000",
};
let receivedData = JSON.parse(apiRespose);
console.log(receivedData.variant_main_image)