我正在尝试使用Skyscanner JsonPath实现(参考https://github.com/Skyscanner/JsonPath-PHP)。
按照他们的指示,我尝试制作了一个小的PHP示例(名为testSkyScanner.php),用这种方式(我在Ubuntu15.10上...)
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
use JsonPath/JsonObject
$theJson = '{
"codiciColore": [{
"id": 2,
"descrizione": "Giallo",
"rgb": "FFFF00",
"priorita": 2,
"situazionePazienti": {
"numeroPazienti": 9,
"numeroPazientiInVisita": 9,
"mediaAttesa": "00:22",
"numeroPazientiInAttesa": 0
}
}, {
"id": 3,
"descrizione": "Verde",
"rgb": "00FF00",
"priorita": 3,
"situazionePazienti": {
"numeroPazienti": 16,
"numeroPazientiInVisita": 9,
"mediaAttesa": "03:03",
"numeroPazientiInAttesa": 7
}
}]
}';
$jsonObject = new JsonObject();
?>我已经以这种方式组织了我的代码...

当我尝试使用php testSkyScanner.php执行它时,我得到了这个错误...
PHP Warning: The use statement with non-compound name 'JsonPath' has no effect in /var/www/html//Test/tmp/MyTestSkyScanner/testSkyScanner.php on line 7
PHP Parse error: syntax error, unexpected '/', expecting ',' or ';' in /var/www/html/Test/tmp/MyTestSkyScanner/testSkyScanner.php on line 7有什么建议吗?提前感谢!
发布于 2017-09-02 03:59:07
PHP Warning: The use statement with non-compound name 'JsonPath' has no effect in /var/www/html//Test/tmp/MyTestSkyScanner/testSkyScanner.php on line 7这个错误告诉您
use JsonPath/JsonObject什么也做不到(也是无效的,见下文)。PHP中没有“导入的名称空间”的概念。use关键字用于创建别名(对于长命名空间很有用),但在使用该类时必须提供完全限定的命名空间。
PHP Parse error: syntax error, unexpected '/', expecting ',' or ';' in /var/www/html/Test/tmp/MyTestSkyScanner/testSkyScanner.php on line 7名称空间使用反斜杠分隔,而不是正斜杠,这就是导致此错误的原因。
您应该完全省略"use“行,改为调用:
$jsonObject = new JsonPath\JsonObject();如果您使用的是Composer,请不要忘记在脚本顶部使用composer自动加载脚本:
require __DIR__ . '/vendor/autoload.php';https://stackoverflow.com/questions/46006973
复制相似问题