0

Hi I am trying to get everything in within the [] brackets. I have tried everything I could find but no luck

{
  "Items": [
    {
      "UID": "XXX-XXX",
      "Code": "USD",
      "CurrencyName": "US Dollar",
      "CurrencyRate": 0.71428000,
      "URI": "https://ar2.api.myob.com/accountright/XXX-XXX/GeneralLedger/Currency/XXX-XXX",
      "RowVersion": "-6496407278109851648"
    }
  ],
  "NextPageLink": null,
  "Count": 1
}

EDIT

My Code

   $getsbCurrencyDetailsclass = new myobsbfunctions($_SESSION['access_token'],api_key);
        $getsbCurrencyDetails = $getsbCurrencyDetailsclass->getResponsenew($cf_uri. "/GeneralLedger/Currency/?" .'$filter' ."=Code%20eq%20'{$docCurrencyType}'");

        
        $getsbCurrencyDetails = json_decode($getsbCurrencyDetails);

        $result=$getsbCurrencyDetails['Items'];
        //print("<pre>".print_r($result,true)."</pre>");
        echo $getsbCurrencyDetails
Benm
  • 9
  • 3

1 Answers1

1

You need to convert the JSON into an array, then manipulate this array. Assuming the text is in $json:

$array=json_decode($json, true);
$result=$array['Items'];

EDIT

I forgot the second parameter to json_decode

Eugen Rieck
  • 64,175
  • 10
  • 70
  • 92
  • I have tried this but i get this error - `Fatal error: Uncaught Error: Cannot use object of type stdClass as array in E:\github\MYOB_API\connection.php:352 Stack trace: #0 {main} thrown in E:\github` – Benm Oct 02 '20 at 09:01
  • added my code in OP above – Benm Oct 02 '20 at 09:04
  • I forgot the second parameter to `json_decode` - please retry. – Eugen Rieck Oct 02 '20 at 09:26
  • No error but I still have the extra info, I only need the items within the []. – Benm Oct 02 '20 at 09:38
  • `Array ( [Items] => Array ( [0] => Array ( [UID] => xxx-xxx [Code] => USD [CurrencyName] => US Dollar [CurrencyRate] => 0.71428 [URI] => https://ar2.api.myob.com/accountright/xxx-xxx/GeneralLedger/Currency/xxx-xxx [RowVersion] => -6496407278109851648 ) ) [NextPageLink] => [Count] => 1 )` – Benm Oct 02 '20 at 09:55
  • You checked `$array`, but you should have checked `$result` – Eugen Rieck Oct 02 '20 at 10:33