-1

I've a json response like this:

'{"success":true,"code":200,"message":"Success","data":[{"title":"title1","productKey":"123","thumbnailUrl":"https://example.com/1.jpg","star":0},{"title":"title2","productKey":"234","thumbnailUrl":"https://example.com/2.jpg","star":0}]}'

above code is in a variable as string

I need just product keys: 123,234;

how can I get product keys from this reponse?

Thanks
Sadegh
  • 327
  • 2
  • 20

1 Answers1

1

Use json_decode to turn it into an associative array.

$jsonString = '{"success":true,"code":200,"message":"Success","data":[{"title":"title1","productKey":"123","thumbnailUrl":"https://example.com/1.jpg","star":0},{"title":"title2","productKey":"234","thumbnailUrl":"https://example.com/2.jpg","star":0}]}';

$json = json_decode($jsonString, true);
$productKeys = [];
foreach($json["data"] as $val)
{
  $productKeys[] = $val["productKey"];
}
Liftoff
  • 24,717
  • 13
  • 66
  • 119