0

I get this JSON back

stdClass Object ( [status] => stdClass Object ( [timestamp] => 2022-11-17T10:41:36.783Z [error_code] => 0 [error_message] => [elapsed] => 1 [credit_count] => 1 [notice] => ) [data] => stdClass Object ( [1] => stdClass Object ( [symbol] => w80iz51y4ka [id] => 1 [name] => omu2f57cwof [amount] => 1 [last_updated] => 2022-11-17T10:41:36.783Z [quote] => stdClass Object ( [GBP] => stdClass Object ( [price] => 0.436996948831 [last_updated] => 2022-11-17T10:41:36.783Z ) [LTC] => stdClass Object ( [price] => 0.201879205801 [last_updated] => 2022-11-17T10:41:36.783Z ) [USD] => stdClass Object ( [price] => 8977 [last_updated] => 2022-11-17T10:41:36.783Z ) ) ) ) )

I dont know how to handle this "stdClass Object". There are a lot in.

At postmen I get this result

{
    "status": {
        "timestamp": "2022-11-17T08:53:52.920Z",
        "error_code": 0,
        "error_message": null,
        "elapsed": 1,
        "credit_count": 1,
        "notice": null
    },
    "data": {
        "2": {
            "symbol": "ymtwz9qdk3",
            "id": 2,
            "name": "9t5ci78gq36",
            "amount": 1,
            "last_updated": "2022-11-17T08:53:52.920Z",
            "quote": {
                "GBP": {
                    "price": 0.9733139411311549,
                    "last_updated": "2022-11-17T08:53:52.920Z"
                },
                "LTC": {
                    "price": 0.564631913659549,
                    "last_updated": "2022-11-17T08:53:52.920Z"
                },
                "USD": {
                    "price": 8956,
                    "last_updated": "2022-11-17T08:53:52.920Z"
                }
            }
        }
    }
}

I How can I convert this to an array in PHP? I test a lot also some solutions from other posts. But I am lost a bit.

Thanks and kind regards Markus

  • 2
    `json_decode($variable,true);` The `true` will convert all into array. – Simone Rossaini Nov 17 '22 at 10:54
  • Define "handle". Are you asking how to get some specific data from it? It's accessible just like any PHP object. But yes if you would rather work with an array you can follow Simone's suggestion above to decode the original JSON into an associative array to begin with, rather than an object. – ADyson Nov 17 '22 at 10:59
  • P.S. [How to extract and access data from JSON with PHP?](https://stackoverflow.com/questions/29308898/how-to-extract-and-access-data-from-json-with-php) may be relevant for you as well, I would guess. – ADyson Nov 17 '22 at 11:00

0 Answers0