0

我正在尝试访问

@角/核心

从 json 文件看起来像波纹管

"dependencies": {
   "@angular/animations": "^6.1.0",
   "@angular/common": "^6.1.0",
   "@angular/compiler": "^6.1.0",
   "@angular/core": "^6.1.0",
   "@angular/forms": "^6.1.0",
   "@angular/http": "^6.1.0",
   "@angular/platform-browser": "^6.1.0",
   "@angular/platform-browser-dynamic": "^6.1.0",
   "@angular/router": "^6.1.0",
   "core-js": "^2.5.4",
   "rxjs": "~6.2.0",
   "zone.js": "~0.8.26"
},

我试过的代码是

    def packageString = readFile("app/package.json")  // read the json file
    def parsedPackageString =  new groovy.json.JsonSlurperClassic().parseText(packageString)

    echo "My Angular Project version $parsedPackageString.dependencies.@angular/core"

但它正在打印依赖项的所有值

我的预期结果是

"^6.1.0",

4

1 回答 1

0

您只需要为parsedPackageString指定属性:

def parsedPackageString =  new groovy.json.JsonSlurperClassic().parseText(packageString).dependencies.'@angular/core'
于 2019-02-13T07:47:56.470 回答