如何使用PHP获取JSON数组中的特定值

时间:2022-10-27 10:22:41

As you see in the image:

如图所示:

如何使用PHP获取JSON数组中的特定值

I've and array of object I think there is JSON array. I want to get only "productThumbnailUrl" on this array and use that in another way.

我和对象数组我觉得有JSON数组。我想在这个数组上只获得“productThumbnailUrl”并以另一种方式使用它。

Can anyone help me to find this value and store it in a separate variable.

任何人都可以帮我找到这个值并将其存储在一个单独的变量中。

I've multiple rows in this array. i only want get "productThumbnailUrl". This value i get in Cokkie section, actually this is the cokkie section which store the cokkie in the name of "CartArray"

我在这个数组中有多行。我只想得到“productThumbnailUrl”。我在Cokkie部分获得的这个值,实际上这是cokkie部分以“CartArray”的名义存储cokkie

3 个解决方案

#1


1  

You can use For loop to loop json data

您可以使用For循环来循环json数据

for(x in json) {
    console.log(json[x].productThumbnailUrl);
}

#2


1  

var x = JSON.parse('{"productThumbnailUrl": "val1", "key2": "val2", "key3": "val3", "key4": "val4"}');

var x = JSON.parse('{“productThumbnailUrl”:“val1”,“key2”:“val2”,“key3”:“val3”,“key4”:“val4”}');

alert (x['productThumbnailUrl']);

alert(x ['productThumbnailUrl']);

var y = x['productThumbnailUrl'];

var y = x ['productThumbnailUrl'];

#3


0  

Let's consider your main array is

让我们考虑你的主阵列是

var products= [your product arr];
products.forEach(
function(product){
console.log(product["productThumbnailUrl"]);
});

it will list your productThumbnailUrls. it will loop through all items.

它会列出你的productThumbnailUrls。它将遍历所有项目。

#1


1  

You can use For loop to loop json data

您可以使用For循环来循环json数据

for(x in json) {
    console.log(json[x].productThumbnailUrl);
}

#2


1  

var x = JSON.parse('{"productThumbnailUrl": "val1", "key2": "val2", "key3": "val3", "key4": "val4"}');

var x = JSON.parse('{“productThumbnailUrl”:“val1”,“key2”:“val2”,“key3”:“val3”,“key4”:“val4”}');

alert (x['productThumbnailUrl']);

alert(x ['productThumbnailUrl']);

var y = x['productThumbnailUrl'];

var y = x ['productThumbnailUrl'];

#3


0  

Let's consider your main array is

让我们考虑你的主阵列是

var products= [your product arr];
products.forEach(
function(product){
console.log(product["productThumbnailUrl"]);
});

it will list your productThumbnailUrls. it will loop through all items.

它会列出你的productThumbnailUrls。它将遍历所有项目。