【问题标题】:Append a value of a JSON inside another JSON in JMeter在 JMeter 中的另一个 JSON 中附加一个 JSON 的值
【发布时间】:2022-08-19 02:42:33
【问题描述】:

通过使用以下脚本,我能够为请求方法生成请求有效负载。

import groovy.json.JsonSlurper
import groovy.json.JsonBuilder
def response = new groovy.json.JsonSlurper().parse(prev.getResponseData())
def builder = new JsonBuilder()
def finalRequest = [:];
def dicomTemp = builder.dicomTemplate
    {
    templateName \"Default\"
    templateDesc \"Default\"
    templateType \"DEFAULT\"
    }
def dicomTags = builder.dicomTaS {
    {
    tagGroup \"0002\"
    tagElement \"0002\"
    tagName \"Media Storage SOP Class UID\"
    updatedOn \"2021-10-05T22:03:36.000+00:00\"
    labelValue 131074
    mandatory \"1\"
    }
    {
    tagGroup \"0002\"
    tagElement \"0010\"
    tagName \"Transfer Syntax UID\"
    tagKeyword \"TransferSyntaxUID\"
    createdOn \"2021-06-02T20:40:59.000+00:00\"
    numericLabel \"00020010\"
    labelValue 131088
    mandatory \"1\"
    }
}
finalRequest.put(\'studyDTO\', true);
finalRequest.put(\'allSites\', true);
finalRequest.put(\'allSubjects\', true);
finalRequest.put(\'allStates\', true);
finalRequest.put(\'allVisits\', true);
finalRequest.put(\'modalities\', response.modalities);
finalRequest.put(\'allModalities\', true);
finalRequest.put(\'allExamDates\', true);
finalRequest.put(\'allSeries\', true);
finalRequest.put(\'transferType\', \"DICOM\");
finalRequest.put(\'sftpLocations\', response.sftpLocations)
finalRequest.put(\'dicomLocations\', response.dicomLocations)
finalRequest.put(\'customFolder\', null)
finalRequest.put(\'folderStructure\', null)
finalRequest.put(\'customFile\', null)
finalRequest.put(\'fileStructure\', null)
finalRequest.put(\'includePS\', null)
finalRequest.put(\'softEditOverride\', true)
finalRequest.put(\'dicomTemplate\', dicomTemp.dicomTemplate)
finalRequest.put(\'dicomTemplate.dicomTags\', [dicomTags.dicomTaS])
vars.put(\'finalPayload\',new groovy.json.JsonBuilder(finalRequest).toPrettyString());

但是这里有两个更正需要,

dicomTags 应该是dicomTemplate 的一个key,但是因为声明dicomTemplate.dicomTags,所以单独放置。如何纠正这种情况?

可以看到第二个值,想包含所有的值

像下面

    标签: json groovy jmeter


    【解决方案1】:

    我认为你需要改变这一点:

    def dicomTags = builder.dicomTaS {
    {
      tagGroup "0002"
      tagElement "0002"
      tagName "Media Storage SOP Class UID"
      updatedOn "2021-10-05T22:03:36.000+00:00"
      labelValue 131074
      mandatory "1"
    }
    {
      tagGroup "0002"
      tagElement "0010"
      tagName "Transfer Syntax UID"
      tagKeyword "TransferSyntaxUID"
      createdOn "2021-06-02T20:40:59.000+00:00"
      numericLabel "00020010"
      labelValue 131088
      mandatory "1"
    }
    }
    

    对此:

    def dicomTags = builder {
        dicomTaS(
                [
                        {
                            tagGroup "0002"
                            tagElement "0002"
                            tagName "Media Storage SOP Class UID"
                            updatedOn "2021-10-05T22:03:36.000+00:00"
                            labelValue 131074
                            mandatory "1"
                        },
                        {
                            tagGroup "0002"
                            tagElement "0010"
                            tagName "Transfer Syntax UID"
                            tagKeyword "TransferSyntaxUID"
                            createdOn "2021-06-02T20:40:59.000+00:00"
                            numericLabel "00020010"
                            labelValue 131088
                            mandatory "1"
                        }
                ]
        )
    }
    

    和这个:

    finalRequest.put('dicomTemplate', dicomTemp.dicomTemplate)
    finalRequest.put('dicomTemplate.dicomTags', [dicomTags.dicomTaS])
    

    对此:

    dicomTemp.dicomTemplate.put('dicomTags', dicomTags['dicomTaS'])
    finalRequest.put('dicomTemplate', dicomTemp.dicomTemplate)
    

    还有don't post code as screenshots 并包括我们重现您的问题所需的一切(即response 对象):How do I ask a good question?

    更多信息:

    【讨论】:

      猜你喜欢
      • 2020-12-29
      • 2019-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多