JSON获得全位数

时间:2015-05-10 05:31:33

标签: json grails

我有一个BigInteger变量,例如chipertext

println "chipherTotalAmount= "+chipertext

结果: enter image description here

然后我将其解析为JSON,结果是

enter image description here

如何以全位数获取该值?

这是我在网络应用中的代码。

def registerItem = RegisterItem.where {
    (dateReceivedItem >= fromDate && dateReceivedItem < toDate)
}.list()

println "registerItem.size = "+registerItem.size()

for (int x = 0; x < registerItem.size(); x++){

    RSA rsa =  new RSA()
    println "x noata .clas = "+registerItem[x].noNota.class
    // BigInteger plaintext = new BigInteger( registerItem[x].noNota.getBytes())

    publickey = new BigInteger(cifuser.publicKey)
    newn = new BigInteger(cifuser.newn)
    privatekey = new BigInteger(cifuser.privateKey)

    BigInteger NoNota = new BigInteger(registerItem[x].noNota.getBytes());
    BigInteger chipherNoNota = rsa.encrypt(NoNota, publickey, newn);
    println "chipherNoNota = "+chipherNoNota

    def totalmountString = registerItem[x].totalAmount.toString()
    println "totalmountString = "+totalmountString
    println "totalmountString = "+totalmountString.class
    BigInteger TotalAmount = new BigInteger(totalmountString.getBytes());
    BigInteger chipherTotalAmount = rsa.encrypt(TotalAmount, publickey, newn);
    println "chipherTotalAmount = "+chipherTotalAmount

    BigInteger SenderName = new BigInteger(registerItem[x].senderName.getBytes());
    BigInteger chipherSenderName = rsa.encrypt(SenderName, publickey, newn);
    println "chipherSenderName = "+chipherSenderName

    registerItem[x].noNota = chipherNoNota.toString()
    registerItem[x].totalAmount = chipherTotalAmount //i cannot parse this to String because at my domain totalAmount was BigInteger
    registerItem[x].senderName = chipherSenderName.toString()
    registerItem[x].discard()
}

这是我的域名

class RegisterItem implements Serializable{

    String noNota
    City destination
    Date dateReceivedItem

    String senderName
    String noTelpSender
    String noHpSender
    String emailSender
    String addressSender
    String descriptionSender

    String receiverName
    String noTlpReceiver
    String noHpReceiver
    String emailReceiver
    String addressReceiver
    String descriptionReceiver

    String deleteFlag = "N"

    BigInteger totalAmount

    String isPay = "Y"

    String useDefault = "Y"

    Date dateCreated
    Date lastUpdated

    String updatedBy = ""
    String createdBy

    static constraints = {
        noTelpSender(nullable:true,blank:true)
        noHpSender(nullable:true,blank:true)
        emailSender(nullable:true,blank:true)
        addressSender(nullable:true,blank:true)
        descriptionSender(nullable:true,blank:true)

        noTlpReceiver(nullable:true,blank:true)
        noHpReceiver(nullable:true,blank:true)
        emailReceiver(nullable:true,blank:true)
        addressReceiver(nullable:true,blank:true)
        descriptionReceiver(nullable:true,blank:true)

        createdBy(blank: false, maxSize: 50)
        lastUpdated(nullable: true)
    }

    def beforeInsert = {
        // createdBy = springSecurityService.principal.username
        dateCreated = new Date()
    }
    def beforeUpdate = {
        // updatedBy = springSecurityService.principal.username
        lastUpdated = new Date()
    }
}

1 个答案:

答案 0 :(得分:0)

如果我是你并热衷于无损转换,我会将其解析为String并使用以下代码String发送:

String.valueOf(bigInt);

bigInt.toString();