我從外部(Reviews-io)腳本生成了這個 JSON: https ://widget.reviews.co.uk/rich-snippet/dist.js
richSnippet({
store: "www.storedigital.local",
sku:"6647;6647_5;6647_4;6647_3;6647_11;6647_10;6647_2;6647_1;6647_9;6647_8;6647_7;6647_6",
data:{
"url": "store.stg.gsd.local/1/silla-replica-eames.html",
"description": ``,
"mpn": "6647",
"offers" :[{
"@type":"Offer",
"availability": "http://schema.org/InStock",
"price": "559",
"priceCurrency": "MXN",
"url": "https://store.stg.gsd.localx/1/silla-replica-eames.html",
"priceValidUntil": "2022-05-26",
}],
"brand": {
"@type": "Brand",
"name": "Not Available",
}
}
})
我需要在“sku”中獲取所有數字字串,然后將它們放入另一個格式相同的變數中(6647;6647_1;6647_2)
我嘗試使用此 JS 獲取數字但不起作用
var skucollection = JSON.parse(richSnippet, function (key, value) {
if (key == "sku") {
return new Sku(value);
} else {
return value;
}
});
你能幫我檢查一下我做錯了什么,以獲取這個 sku 的值字串嗎?
uj5u.com熱心網友回復:
JSON.parse 是不是太多了?,在內部處理它(確實是一個 JSON)
var richSnippet = {
store: 'www.storedigital.local',
sku: '6647;6647_5;6647_4;6647_3;6647_11;6647_10;6647_2;6647_1;6647_9;6647_8;6647_7;6647_6',
algomas: [],
data: {
url: 'store.stg.gsd.local/1/silla-replica-eames.html',
description: ``,
mpn: '6647',
offers: [
{
'@type': 'Offer',
availability: 'http://schema.org/InStock',
price: '559',
priceCurrency: 'MXN',
url: 'https://store.stg.gsd.localx/1/silla-replica-eames.html',
priceValidUntil: '2022-05-26',
},
],
brand: {
'@type': 'Brand',
name: 'Not Available',
},
},
};
var test;
Object.keys(richSnippet).forEach((key) => {
if (key == 'sku') {
test = richSnippet[key];
}
});
console.log('test', test);
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/476726.html
標籤:javascript 数组 json 马金托 得到
上一篇:在Magento網站的類別頁面中設定noindexnofollow
下一篇:當我升級Magento2.4.4時,我得到了棄用的功能:回傳型別Composer\Repository\CompositeRepository::count()
