JSON封装

需要封装成的JSON格式

{
        "transaction":
        {
            "timeStamp": 130409573,
            "amount": 1000000,
            "fee": 50000,
            "recipient": "NBDQ3Y3AQXETI3B5CF7FIB5OFXVDYRCUMBVMAI4C",
            "type": 257,
            "deadline": 130109573,
            "message":
            {
                "payload": "",
                "type": 1
            },
            "version":1744830466,
            "signer": "4e3ad5f689e140679819d432a2017d22580b456999f988ae951e8ee9e9738ab6",
            "mosaics":[{
                "mosaicId":{
                    "namespaceId": "xarbon",
                    "name": "xcu"
                },
                "quantity": 1
            },{
                "mosaicId":{
                    "namespaceId": "nem",
                    "name": "xem"
                },
                "quantity": 1000000
            }]
        },
        "privateKey": "040f55089ba35cc064909759ac86d4318eb316ab5554417e7f6d2767ee408f8c"
}

封装后的代码

 Map resultMap = new HashMap<>();
        Map transactionMap = new HashMap<>();
        Map mosaicMap = new HashMap<>();
        Map mosaicIdMap = new HashMap<>();
        Map messageMap = new HashMap<>();
        ArrayList>  mosaicsLst = new ArrayList();
        resultMap.put("transaction",transactionMap);
        transactionMap.put("timeStamp",130409573);
        transactionMap.put("amount",1000000);
        transactionMap.put("fee",50000);
        transactionMap.put("recipient","NBDQ3Y3AQXETI3B5CF7FIB5OFXVDYRCUMBVMAI4C");
        transactionMap.put("type",257);
        transactionMap.put("deadline",130109573);
        transactionMap.put("message",messageMap);
        messageMap.put("payload","");
        messageMap.put("type",1);
        transactionMap.put("version",1744830466);
        transactionMap.put("signer","4e3ad5f689e140679819d432a2017d22580b456999f988ae951e8ee9e9738ab6");
        transactionMap.put("mosaics",mosaicsLst);
        transactionMap.put("privateKey","040f55089ba35cc064909759ac86d4318eb316ab5554417e7f6d2767ee408f8c");
        mosaicMap.put("mosaicId",mosaicIdMap);
        mosaicMap.put("quantity",1000000);
        mosaicIdMap.put("namespaceId","xarbon");
        mosaicIdMap.put("name","xcu");
        mosaicsLst.add(mosaicMap);

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(JSON封装)