[英]Replaceall JSON in Groovy for Jenkins
hoping you all ok and your family as well, i need to ask something kinda noob.希望你和你的家人都好,我需要问一些菜鸟。 I'm working right now with Groovy for some proyect in jenkins.我现在正在为 jenkins 中的一些项目使用 Groovy。 My json file has a lot names: "Ingress_1", "Ingress_2" and so on, so i'll try with the famous replaceAll but nothing happens:我的 json 文件有很多名称:“Ingress_1”、“Ingress_2”等等,所以我会尝试使用著名的 replaceAll 但没有任何反应:
Here's the code:这是代码:
import groovy.json.JsonSlurper
if(the_suite.equals("Asset_important"))
{
def process =["cat",".blabla/jsonfile.json"].execute()
def jsonSlurper = new JsonSlurper()
List<String> artifacts = new ArrayList<String>()
def object_a = jsonSlurper.parseText(process.text)
def object = object_a.replaceAll(/_/, ' ')
assert object instanceof Map
for(i=0;i<object.data.size();i++){ artifacts.add(object.data[i].feature)
}
I already tried with replaceAll("/_/", ' ')
我已经尝试过replaceAll("/_/", ' ')
Thanks for read this:)感谢您阅读本文:)
replaceAll()
is only defined for String
, but you are trying to use it on the result of JsonSlurper.parseText()
, which is of type Object
. replaceAll()
仅为String
定义,但您试图在JsonSlurper.parseText()
的结果上使用它,其类型为Object
。
This should work:这应该有效:
def object = jsonSlurper.parseText(process.text.replaceAll('_', ' '))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.