php jsonpath add,使用php jsonpath解析JSON

我正在尝试使用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路径…

建议?

先感谢您 …

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值