PHP JSON BigInt编码 [英] PHP JSON BigInt encoding
本文介绍了PHP JSON BigInt编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像这样的数组:
I have array like:
$array = ['id' => '76561198165327575'];
我需要它在客户端的JavaScript中工作.所以我想用 JSON_NUMERIC_CHECK
对其进行编码:
And I need it to work in JavaScript on client side. So I'm trying to encode it with JSON_NUMERIC_CHECK
:
json_encode($array, JSON_NUMERIC_CHECK);
并得到如下结果:
{"id":7.6561198165328e+16}
但是应该是:
{"id":76561198165327575}
怎么了?
(Azure,Windows,5.6)
(Azure, Windows, 5.6)
推荐答案
JSON_NUMERIC_CHECK
基本上告诉编码器如果看起来像数字,则将其编码为数字":
JSON_NUMERIC_CHECK
basically tells the encoder "If it looks like a number, encode it as a number":
php > $x = '123456789012234567890';
php > echo json_encode($x, JSON_NUMERIC_CHECK);
1.2345678901223e+20
php > echo json_encode($x);
"123456789012234567890"
并且由于您的数字超出了平台上INT的可表示范围,因此您将获得浮点数.
And since your number exceeds the representable range for an INT on your platform, you get a float instead.
这篇关于PHP JSON BigInt编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文