处理PHP中由FQL返回的大型用户ID [英] Handling big user IDs returned by FQL in PHP
问题描述
我正在使用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屋!