Skip to content
Advertisement

Handling big user IDs returned by FQL in PHP

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.

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

Advertisement

Answer

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)
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement