PHP函数json_decode将点后的零浮点值解码为int [英] PHP function json_decode decodes float value with zeros after point as int
问题描述
我有一个JSON字符串,其中包含一些具有以下值的密钥:123.00.当我使用json_decode函数时,我得到的解码字符串的前一个键等于123,而不是123.00.有没有一种方法可以正确解码这些值而不用引号引起来?
I have a JSON string that contains some key with the following value: 123.00. When I use json_decode function I get the decoded string where the previous key equal to 123, not to 123.00. Is there a way to correct decode such values without wrapping into quotes?
推荐答案
当前作为PHP错误被提出:
This is currently being brought up as a PHP bug:
错误报告: https://bugs.php.net/bug.php ?id = 50224
将来,可能会提供通过options
参数传递标志的功能,以进行更严格的键入.但是,目前,用引号将其包装就足够了.
In the future, there may be functionality to pass a flag through the options
parameter for stricter typing. For now, however, wrapping it in quotes will have to suffice.
这篇关于PHP函数json_decode将点后的零浮点值解码为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!