Im trying to get the price of a stock qoute using json_decode and file_get_contents. im trying to get the price with associative arrays but I get undefined index errors and quite frankly I am stuck. my code:
$jsondata =file_get_contents("http://finance.yahoo.com/webservice/v1/symbols/wmt/quote?format=json");
$json = json_decode($jsondata, true);
$list = $json['list'];
$resource = $list['resources'];
$resource = $resource['resource'];
$fields = $resource['fields'];
$price = $fields['price'];
echo $price;
the JSON:
{
list : {
meta : {
type : "resource-list",
start : 0,
count : 1
},
resources : [{
resource : {
classname : "Quote",
fields : {
name : "Wal-Mart Stores, Inc. Common St",
price : "68.570000",
symbol : "WMT",
ts : "1440014635",
type : "equity",
utctime : "2015-08-19T20:03:55+0000",
volume : "16333364"
}
}
}
]
}
}
any help will be greatly appreciated.