我需要总结" initialContractualPrice"的所有值。在http://www.base.gov.pt/base2/rest/contratos?&sort(-publicationDate)。
我想在php中进行操作。
谁知道可以帮助我?
非常感谢你;)
答案 0 :(得分:1)
尝试
$data = file_get_contents('http://www.base.gov.pt/base2/rest/contratos?&sort(-publicationDate)');
$data = json_decode($data);
foreach($data as $dat){
echo $dat->publicationDate;
}
您还可以使用print_r
或var_dump
查看结构
答案 1 :(得分:0)
这应该照顾它。
// Get json from url
$url = 'http://www.base.gov.pt/base2/rest/contratos?&sort(-publicationDate)';
$content = file_get_contents($url);
// Decode json into an array
$json = json_decode($content, true);
// Set default
$total = 0;
// Loop through the array created when decoding json
foreach ($json as $key)
{
// remove symbol from the end leaving only digits
$value = substr(utf8_decode($key['initialContractualPrice']), 0, -1);
// remove the decimal point
$value = str_replace('.', '', $value);
// replace the comma with a decimal point
$value = str_replace(',', '.', $value);
// add this number to the total value
$total += $value;
}
echo $total;