您可能需要做這樣的事情:
import groovy.json.JsonBuilder
import groovy.json.JsonSlurper
def jsonStr = '{"scopeId":" ","scopeType":" ","userId":" ","fieldToBeEncryptedList":[{"srNo":" ","fieldName":" ","value":" ","echoField":" "}]}'
def slurp = new JsonSlurper().parseText(jsonStr)
def builder = new JsonBuilder(slurp)
builder.content.scopeId = 'val1'
builder.content.fieldToBeEncryptedList[0].srNo = 'val2'
println builder.toPrettyString()
輸出:
{
"fieldToBeEncryptedList": [
{
"echoField": " ",
"fieldName": " ",
"srNo": "val2",
"value": " "
}
],
"scopeId": "val1",
"scopeType": " ",
"userId": " "
}
需要更多信息!用例子會很好。它可以在沒有Groovy腳本的情況下完成。如果您想要全面使用Groovy,請查看以下內容:https://siking.wordpress.com/2013/07/05/dynamically-create-elements-in-a-soapui-request-json-version/ – SiKing