所以我在 WAMP 环境中使用 php 5.2.6。
我正在尝试使用 json_decode 函数将 json 字符串放入数组中。 JSON 来自其他地方的 REST API,因此我无法控制 JSON 字符串的格式。这是我尝试使用的 json 字符串之一的示例:
[{
"webinarKey":795855906,
"sessionKey":100000000041808257,
"startTime":"2011-12-16T13:56:15Z",
"endTime":"2011-12-16T14:48:37Z",
"registrantsAttended":2
}]
我特别关注这里的 sessionKey 值。 PHP 将该值视为浮点数,我似乎无法执行任何操作来检索原始值。
我尝试过以下方法:
json_decode($json, true, 512, JSON_BIGINT_AS_STRING);
# This produces the following error because my php version isn't up to snuff and I
# can't upgrade to the version required
# Warning: json_decode() expects at most 2 parameters, 4 given
我也尝试过这个:
$json_obj = json_decode($json, true);
number_format($json_obj[0]["sessionKey"], 0, '.', '');
# This results in precision issues where the value was 100000000041808257
# but is number_formated out as 100000000041808256
正如我所说,升级到 php 5.4(支持 4 个参数 json_decode 调用)不是一个选择。请帮忙!
Thanks!