-1

I want to use json with php but I don't know how to access it

Here is my code

$ch7 = curl_init();
curl_setopt($ch7, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch7, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch7, CURLOPT_URL, 'https://api.coingecko.com/api/v3/global');
$result7 = curl_exec($ch7);
curl_close($ch7);
$obj7 = json_decode($result7);

Here is the json

    {
  "data": {
    "active_cryptocurrencies": 6338,
    "upcoming_icos": 0,
    "ongoing_icos": 50,
    "ended_icos": 3375,
    "markets": 575,
    "total_market_cap": {
      "btc": 31264669.404227894,
      "eth": 986229572.8311379,
      "ltc": 8326834496.047988,
      "bch": 2980419662.8658423,
      "bnb": 6485631120.709941
    },
    "total_volume": {
      "btc": 3784938.672480205,
      "eth": 119394144.29398768,
      "ltc": 1008056650.0144182
    },
    "market_cap_percentage": {
      "btc": 59.63238491010178,
      "eth": 11.663971433816743,
      "ada": 2.4794373376051837    },
    "market_cap_change_percentage_24h_usd": 7.202574893019179,
    "updated_at": 1614796183
  }
}

Can you help access for example data->ongoing_icos ?

dbc
  • 104,963
  • 20
  • 228
  • 340
Lep
  • 1
  • 2
  • I removed the [tag:json.net] tag as this is specifically for questions relating to the .Net package [Json.NET](https://www.newtonsoft.com/json). – dbc Mar 03 '21 at 19:11
  • 1
    Perhaps you're looking for [How do I extract data from JSON with PHP?](https://stackoverflow.com/q/29308898/3744182), which suggests `echo $obj7->upcoming_icos;` – dbc Mar 03 '21 at 19:15
  • 1
    ok the answer $obj7->data->upcoming_icos ...thank you – Lep Mar 03 '21 at 19:43

1 Answers1

-1
 $obj7->data->upcoming_icos 
Met Br
  • 634
  • 5
  • 9
  • Yeah my bad in copy of the code. still have the issue to access it – Lep Mar 03 '21 at 19:05
  • try to var_dump $result7 before and read it before json_decoding you can maybe find some forbidden or simiilar, maybe they need authentication – Met Br Mar 03 '21 at 19:07
  • ok and then i ll use $obj7['data']['upcoming_icos'] for example ? – Lep Mar 03 '21 at 19:09
  • if coingecko.com needs authentication you might need to use headers like login to get the data ---- you can use arrows -> like this after php returns json object – Met Br Mar 03 '21 at 19:11
  • It doesn't need authentication. So $obj7->data->upcoming_icos Thank you for your help :D – Lep Mar 03 '21 at 19:39