简体   繁体   中英

Get the values from json string in pipeline groovy script

I had json string value. I need to get the values from the json string. I have to try to convert the json string to json object and then get the value.

I have try the below steps to convert the json string into json object.

import groovy.js
def slurper = new JsonSlurper().parseText(str).on.JsonSlurper

But I have facing below error while get the values.

java.lang.IllegalArgumentException: Could not instantiate {message=org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: unclassified field java.lang.String id} for EchoStep(message: String): java.lang.ClassCastException: org.jenkinsci.plugins.workflow.steps.EchoStep.message expects class java.lang.String but received class org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException.

Kindly give a better suggestion to get the values from json string in groovy

Note:I didn't restrict script approval.

First, I find that Jenkins plays better with JsonSlurperClassic.

def slurper = new JsonSlurper().parseText(str) is all you need to make the json object, which is an odd mappy-listy object. You can reference it like you would a map that had arrays in it: slurper.mapvalone[0].mapvaltwo[0] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM