如何在angular 2+中使用功能齐全的JsonPath?

问题描述

我关注了https://www.npmjs.com/package/jsonpath。尝试了一种包含外部js文件的方法,但是没有运气。

解决方法

导入jsonPath在-

之后起作用
import * as jsonPath from 'jsonpath/jsonpath';

JsonPath长毛绒也可以使用JSONPath-plus,与Jsonpath一样。我有以下适用于我的代码段-

安装JSONPath-plus

npm install jsonpath-plus

angular.json文件

"scripts": [
    "node_modules/jsonpath-plus/dist/index-umd.js","src/assets/js/jsonpath.js"
]

jsonpath.js具有以下代码-

function jsonPath() {
  return JSONPath;
}

现在在ts文件中使用此功能,如下所示进行声明-

declare const jsonPath: any;
// use it like
 jsonPath().JSONPath(path,json);

 

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...