简体   繁体   中英

Groovy - JSONSlurper parsing json

I have problem with my SoapUI Groovy script. I have following json (simplified):

{  
"data":{  
  "XXX":[...]
  "YYY":[...]

},
"next":"ffawef234fava23r"
}

I have values of XXX and YYY in my previously TestStep as request parameters and I extract it properly as list of string, but my problem is that I need to extract content of data.XXX and data.YYY, but when I want to do this in loop I always get null. My code:

def content = new JsonSlurper().parseText(response)
def ids = extracted_ids.split(';')     //List of IDs in response above {XXX,YYY}
for (id in ids){
                    log.info id // XXX
                    log.info content.data.'XXX'   //this works 
                    log.info content.data.id      //this not
}

Is there any option to pass this "id" in loop to content.data. {id} to get any content instead of null

Kind Regards

你只需要做

log.info content.data."$id"

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