php - 接收长整数值时出现json值错误
问题描述
我正在使用大整数数组向服务器发送数组 JSON 请求,当我收到它们并解码 JSON 时,它将整数值转换为科学记数法格式,我正在使用 php 函数。
{
"friend_ids": [2719267598135496,2719267598135497]
}
(
[friend_ids] => Array
(
[0] => 2.7192675981355E+15
[1] => 2.7192675981355E+15
)
)
这是我收到此值的 JSON 请求。我希望这与我发送到服务器的方式相同
解决方案
PHP 有时会遇到较大数字的问题。幸运的是, json_decode 有一个选项可以将大数转换为字符串:
json_decode($json, TRUE, 512, JSON_BIGINT_AS_STRING);
将返回这个:
array(1) {
["friend_ids"]=>
array(2) {
[0]=>
string(16) "2719267598135496"
[1]=>
string(16) "2719267598135497"
}
}
推荐阅读
- python - 当您尝试通过 POST 方法保存在 vars 中时,Django 不返回任何内容
- android - 如何检查对象是否具有特定属性
- python - 用 [ ] 解压 python 元组
- javascript - 使用房间时清除 Socket React 应用程序中的消息输入
- c++ - 如何将可变参数放入具有继承的元素向量?
- c - 有没有更聪明的方法来声明我的 15 个整数
- regex - 正则表达式用引号和冒号分割
- java - 如何使用循环将句子分成单个单词并将它们单独发送到 Java 中的 ArrayList 中?
- reactjs - react-router:如何让 activeClassName 为非精确路由工作?
- c++ - 调用单例时未定义的引用