Home > Mobile >  unable to get specific data from json object
unable to get specific data from json object

Time:09-22

I'm trying to get the value for acquired and assign it to $acquired. I've tried $acquired = $content['response']['item_json']['acquired']; without success. Below demonstrates the sample data and how I've tried to retrieve it.

<?php

// sample data from curl call
$result = '{"response":{"item_json":"[{ \"accountid\":\"123\",\"itemid\":\"456\",\"quantity\":1,\"originalitemid\":\"789\",\"itemdefid\":\"100\",\"appid\":101112,\"acquired\":\"20210921T175213Z\",\"state\":\"\",\"origin\":\"external\",\"state_changed_timestamp\":\"20210921T175213Z\" }]"}}';

// lets work with this data

$content = json_decode($result['response']['item_json']['acquired'], true);

var_dump($content);

?>

CodePudding user response:

item_json is a nested JSON string, you need to decode it.

$content = json_decode($result, true);
$result2 = json_decode($content['response']['item_json'], true);
var_dump($result2);

CodePudding user response:

Try it.

$content = json_decode($result, true);
$result2 = json_decode($content['response'], true);
$result3 = json_decode($result2['item_json'], true);
var_dump($result3);
  • Related