在 PHP 中处理 FQL 返回的大用户 ID [英] Handling big user IDs returned by FQL in PHP

查看:23
本文介绍了在 PHP 中处理 FQL 返回的大用户 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 FQL 从 Facebook 检索用户列表.为了保持一致性,我将结果作为 JSON.这会导致一个问题——因为返回的 JSON 将用户 ID 编码为数字,json_decode() 会将这些数字转换为浮点值,因为有些数字太大而无法放入 int;当然,我需要这些 ID 作为字符串.

I'm using FQL to retrieve a list of users from Facebook. For consistency I get the result as JSON. This causes a problem - since the returned JSON encodes the user IDs as numbers, json_decode() converts these numbers to floating point values, because some are too big to fit in an int; of course, I need these IDs as strings.

由于 json_decode() 在不接受任何行为标志的情况下做自己的事情,我不知所措.有关如何解决此问题的任何建议?

Since json_decode() does its own thing without accepting any behavior flags, I'm at a loss. Any suggestions on how to resolve this?

推荐答案

json_decode() 可以将大整数转换为字符串,如果你在函数调用中指定了一个标志:

json_decode() can convert large integers to strings, if you specify a flag in the function call:

$array = json_decode($json, true, 512, JSON_BIGINT_AS_STRING)

这篇关于在 PHP 中处理 FQL 返回的大用户 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆