我正在尝试使用jsonpath解析
PHP中的JSON ….
我的JSON来自于此
(这里剪切/粘贴太长了,但你可以在浏览器会话中看到它……)
JSON是一个有效的JSON(我已经使用https://jsonlint.com/验证了它……).
我已经使用http://www.jsonquerytool.com/尝试了jsonpath表达式,所有看起来都很好,但是当我把所有的PHP代码示例放在下面….
ini_set('display_errors', 'On');
error_reporting(E_ALL);
require_once('json.php'); // JSON parser
require_once('jsonpath-0.8.0.php'); // JSONPath evaluator
$url = 'https://servizionline.sanita.fvg.it/tempiAttesaService/tempiAttesaPs';
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_PROXY, '');
$data = curl_exec($ch);
curl_close($ch);
$parser = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
$o = $parser->decode($data);
$xpath_for_parsing = '$..aziende[?(@.descrizione=="A.S.U.I. - Trieste")]..prontoSoccorsi[?(@.descrizione=="Pronto Soccorso e Terapia Urgenza Trieste")]..dipartimenti[?(@.descrizione=="Pronto Soccorso Maggiore")]..codiciColore[?(@.descrizione=="Bianco")]..situazionePazienti..numeroPazientiInAttesa';
$match1 = jsonPath($o, $xpath_for_parsing);
//print_r($match1);
$match1_encoded = $parser->encode($match1);
print_r($match1_encoded);
$match1_decoded = json_decode($match1_encoded);
//print_r($match1_decoded);
if ($match1_decoded[0] != '') {
return $match1_decoded[0];
}
else {
return "N.D.";
}
?>
…没有打印任何值…只是一个“假”值.
当我把它放在我的PHP代码中时,我的jsonpath表达式出了问题:出现的错误如下
Warning: Missing argument 3 for JsonPath::evalx(), called in /var/www/html/OpenProntoSoccorso/Test/jsonpath-0.8.0.php on line 84 and defined in /var/www/html/OpenProntoSoccorso/Test/jsonpath-0.8.0.php on line 101
Notice: Use of undefined constant descrizione - assumed 'descrizione' in /var/www/html/OpenProntoSoccorso/Test/jsonpath-0.8.0.php(104) : eval()'d code on line 1
可能我要逃避/引用我的jsonpath在PHP中使用它但我不知道如何……任何建议都值得赞赏…
注意:我需要使用jsonpath表达式,如?(@ .descrizione ==“A.S.U.I. – Trieste”),我不能使用“位置”json路径…
建议?
先感谢您 …