具有以下JSON:
def jsonString = '{"studyDTO":{"studyId":191,"studyCode":"test_ispptest2"},"sites":[{"studyId":191,"siteRecid":16521,"siteId":"11001"}],"allSubjects":true,"states":null,"visits":[{"studyId":191,"visitSubmitName":"baseline","visitDisplayName":"Baseline","orderOfDisplay":10}],"modalities":null,"examDates":null,"series":null,"transferType":null,"sftpLocations":[],"dicomLocations":[],"fileSystemLocations":[],"rawFileSystemLocations":[],"customFolder":null,"folderStructure":null,"customFile":null,"fileStructure":null,"includePS":null}'
希望使用数据源中的整数动态更新"orderOfDisplay":10
的值。
def jsonConvert = new JsonSlurper();
def object = jsonConvert.parseText(jsonString);
def builder = new JsonBuilder(object)
builder.content.visits[0].orderOfDisplay = 23
[23仅为示例。我运行此程序10次,每次值都将发生变化]
log.info(builder.toPrettyString());
类似于post here,但在我的例子中,我试图更新一个整数。
更新后我得到的错误是,
{
"studyDTO": {
"studyId": 191,
"studyCode": "test_ispptest2"
},
"sites": [
{
"studyId": 191,
"siteRecid": 16521,
"siteId": "11001"
}
],
"allSubjects": true,
"states": null,
"visits": [
{
"studyId": 191,
"visitSubmitName": "cycle_1",
"visitDisplayName": "Cycle 1",
"orderOfDisplay": "23"
}
],
"modalities": null,
"examDates": null,
"series": null,
"transferType": null,
"sftpLocations": [
],
"dicomLocations": [
],
"fileSystemLocations": [
],
"rawFileSystemLocations": [
],
"customFolder": null,
"folderStructure": null,
"customFile": null,
"fileStructure": null,
"includePS": null
}
值23用引号括起来
1条答案
按热度按时间snvhrwxg1#
我无法使用Groovy 3.0.11附带的JMeter 5.5重现它,所以请仔细检查您的软件版本,也许您正遭受某种形式的Jar Hell