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

时间:2015-07-09 18:15:46

标签: json groovy jsonbuilder

我正在寻找可以转换为以下JSON

的对象的定义(结构)
<html>
    <head>
        <script src="https://domain.com/socket.io/socket.io.js"></script>
        <script>
            $(function(){
                var socket = io('https://domain.com:443', {
                    path: '/socket.io'
                });
            });
        </script>
    </head>
    <body>
        ...
    </body>
</html>

1 个答案:

答案 0 :(得分:0)

如果你正在寻找一个如何使用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()

您可能对如何创建没有root权限的JSON感到困惑。答案是:通过传递地图。