所以我在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调用)不是一种选择。请帮忙!
谢谢!