如果使用Slurper通过字符串传递Xpath,如何从JSON获取数组值

时间:2018-06-21 13:34:40

标签: json groovy soapui

解析后的Json响应

String Json= consents:[[id:740, duration:FixedPeriod, status:Active]], [[id:740, duration:FixedPeriod, status:Active]] [[id:740, duration:FixedPeriod, status:Active]] 

String Xpath = consents.id[0]

我的代码如下

json = slurper.parseText(resvalue1.toString())  

 String[] XpathSplit = arSpRt[1].split(["\\."]) // xpath [0] is xpath od field in response
                    log.info "Xpath[1]"+ arSpRt[1]          // xpth[1] expected value of string


                log.info "XpathSplit  " + XpathSplit

                        for(j=0;j<XpathSplit.length;j++){
                        log.info "XpathSplit[j]  "+XpathSplit[j].toString()
                        json = json.(XpathSplit[j])                         
                             log.info "ActualValue ####" +json                      
                            }

因此,如果我仅将"consents.id"从字符串中放入,它会将我的所有ID返回给我,但我想将consents.id[0]作为第一个值,但它将返回null

0 个答案:

没有答案