Why would you use a string in JSON to represent a decimal number

前端 未结 4 1106
借酒劲吻你
借酒劲吻你 2020-11-29 20:59

Some APIs, like the paypal API use a string type in JSON to represent a decimal number. So \"7.47\" instead of 7.47.

Why/when would this b

4条回答
  •  庸人自扰
    2020-11-29 21:31

    The reason I'm doing it is that the SoftwareAG parser tries to "guess" the java type from the value it receives.

    So when it receives

    "jackpot":{
     "growth":200,
     "percentage":66.67
    }
    

    The first value (growth) will become a java.lang.Long and the second (percentage) will become a java.lang.Double

    Now when the second object in this jackpot-array has this

    "jackpot":{
     "growth":50.50,
     "percentage":65
    }
    

    I have a problem.

    When I exchange these values as Strings, I have complete control and can cast/convert the values to whatever I want.

提交回复
热议问题