Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从PHP中的API响应转换为浮点数,需要整数_Php_Json - Fatal编程技术网

从PHP中的API响应转换为浮点数,需要整数

从PHP中的API响应转换为浮点数,需要整数,php,json,Php,Json,我正在调用一个外部API并成功获得结果。然而,导致数值的一个特定字段被更改为浮点数 API调用后,我将继续执行以下操作: print_r($response); // Decode the response $responseData = json_decode($response, TRUE); $ids= $responseData[0][id]; echo $ids; 我得到的结果如下: [{"id":629378047925027252,"name":"Pizza Hut"}]

我正在调用一个外部API并成功获得结果。然而,导致数值的一个特定字段被更改为浮点数

API调用后,我将继续执行以下操作:

print_r($response);

// Decode the response
$responseData = json_decode($response, TRUE);

$ids=  $responseData[0][id];
echo $ids;
我得到的结果如下:

[{"id":629378047925027252,"name":"Pizza Hut"}]
但是对于特定的
id
部分,结果是
6.2937804792503E+17

我想检索上面响应
id
中显示的值。

json\u decode()
默认情况下,将太大的整数(
PHP\u INT\u MAX
)转换为浮点数。您可以使用
JSON\u BIGINT\u AS\u STRING
将它们转换为字符串。见:


由于某些原因,将
null
作为第三个参数传递不会强制它使用默认值(512),因此我传递了512。

尝试在JSON\u decode options参数中使用JSON\u BIGINT\u作为字符串
请参见

谢谢您的帮助。正如解释的那样,你应该接受一个答案。谢谢
$responseData = json_decode($response, true, 512, JSON_BIGINT_AS_STRING);