如何在groovy中使用JsonBuilder创建现有的JSON



我正在寻找对象的定义(结构),可以转换为以下JSON

 {
    "header":{
        "callbackUrl":"",
        "clientOrderId":"A565132",
        "clientOriginationId":"2345FE",
        "serviceProvider":"VERIZON",
        "transactionId":"EEDT44567"
    },
    "customer": {
        "nationalIdType":"",
        "nationalId":"",
        "addresses":[
            {
                "type":"WORK",
                "postalCode":"330066"
            }
        ],
        "serviceProviderAuthentication":[
            {
                "passcode":"",
                "securityQuestion":"",
                "securityAnswer":""
            }
        ]
    },
    "accountPhoneNumber":"",
    "accountNumber":""
}

如果您正在寻找如何使用JsonBuilder创建您所给出的JSON的示例,这里是

def json = new groovy.json.JsonBuilder()
json header: [
        callbackUrl:"",
        clientOrderId:"A565132",
        clientOriginationId:"2345FE",
        serviceProvider:"VERIZON",
        transactionId:"EEDT44567"
    ],
    customer:[
        nationalIdType:"",
        nationalId:"",
        addresses: [
            [
                type:"WORK",
                postalCode:"330066"
            ]
        ],
        serviceProviderAuthentication:[
            [
                passcode:"",
                securityQuestion:"",
                securityAnswer:""
            ]
        ]
    ],
    accountPhoneNumber:"",
    accountNumber:""
json.toString()

你可能对如何创建一个没有根的JSON感到困惑。答案是:通过传递一个映射。

相关内容

  • 没有找到相关文章

最新更新