I would like to follow prices of stocks im interested in with a very simple php file. For this im trying to call certain data from a jsonld file, but unable to do so. Thats mostly because i cant set the correct order.
Here is my php code:
<?
// Get the contents of the JSON file
$strJsonFileContents = file_get_contents("data.jsonld");
$datas = json_decode($strJsonFileContents, True);
//var_dump($datas); // print array
$dataname = $datas->currency[ALGYO];
$dataprice = $datas->currency[ALGYO]->price;
echo $data;
?>
I’ve called the file, can echo with var_dump.
The Json file can be seen here
What i want to do is to call the currency ALGYO, and its price, then in another table or line call lets say ACSEL and its price and so on. I’ll only call some certain elements so a list of all elements is not what im looking for. Could someone show me the way? Thanks in advance.
for those who dont want to follow pastebin link im also leavong a readiable version of json below.
{"@context": "http://schema.org",
"@type": "WebPage",
"name": "BORSA",
"mainEntity": {
"@type": "ItemList",
"name": "BORSA",
"itemListElement": [
{
"@type": "ExchangeRateSpecification",
"currency": "ALGYO",
"currentExchangeRate": {
"@type": "UnitPriceSpecification",
"price": 26.14,
"priceCurrency": "TRY"
}
},
{
"@type": "ExchangeRateSpecification",
"currency": "ARZUM",
"currentExchangeRate": {
"@type": "UnitPriceSpecification",
"price": 24.74,
"priceCurrency": "TRY"
}
},
{
"@type": "ExchangeRateSpecification",
"currency": "ACSEL",
"currentExchangeRate": {
"@type": "UnitPriceSpecification",
"price": 22.9,
"priceCurrency": "TRY"
}
},
{
"@type": "ExchangeRateSpecification",
"currency": "ADANA",
"currentExchangeRate": {
"@type": "UnitPriceSpecification",
"price": 12.19,
"priceCurrency": "TRY"
}
},
{
"@type": "ExchangeRateSpecification",
"currency": "ADBGR",
"currentExchangeRate": {
"@type": "UnitPriceSpecification",
"price": 8.62,
"priceCurrency": "TRY"
}
},
{
"@type": "ExchangeRateSpecification",
"currency": "PAMEL",
"currentExchangeRate": {
"@type": "UnitPriceSpecification",
"price": 22.02,
"priceCurrency": "TRY"
}
}
]
}
}
2
Answers
Although you say you don’t want a list of all elements is not what im looking for, if you want to pick out specific ones in your own order it may be easier.
This just extracts the currentExchangeRate sub-array and indexes it by the currency…
gives…
You could use a function, which allows you to get ‘item'(stock) specific data from the json.
You can(should) tailor the function to fit your needs, here’s an example that searches for an item and returns its price: