[英]Get data from Local Storage
I've the following data in my local storage:我的本地存储中有以下数据:
[{
"event": "addToCart",
"eventLabel": "Test Product",
"ecommerce": {
"currencyCode": "USD",
"add": {
"products": [{
"name": "Test Product",
"id": "78789",
"price": "429.00",
"category": "Catalog Page",
"list": "Massage\/Massage Chairs\/Portable Massage Chairs",
"quantity": "1"
}]
}
}
}]
and I need to access to the value of ecommerce
.我需要获得
ecommerce
的价值。 So obtaining the following data:于是得到以下数据:
"ecommerce": {
"currencyCode": "USD",
"add": {
"products": [{
"name": "Test Product",
"id": "78789",
"price": "429.00",
"category": "Catalog Page",
"list": "Massage\/Massage Chairs\/Portable Massage Chairs",
"quantity": "1"
}]
}
}
How can I do it?我该怎么做?
First you have to parse the json you have首先,您必须解析您拥有的 json
var data = JSON.parse(json);
then you can access any data key and values like this:然后您可以访问任何数据键和值,如下所示:
var ecom = data.ecommerce
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.