带有JSON_BIGINT_AS_STRING和object_get_vars的json_decode无法访问数组键

时间:2017-02-07 16:23:54

标签: php json

我有这段代码:

$test = json_decode('{"1229410050415660":"This works just fine","87402531":"This does not"}', false, 512, JSON_BIGINT_AS_STRING);

echo $test->{87402531}; // works

$test = get_object_vars($test);   

echo $test[1229410050415660]; //doesn't work
echo $test["1229410050415660"]; // works!!   

echo $test[87402531]; //doesn't work
echo $test["87402531"]; //doesn't work either

$test[87402531] = 'This should work now.';

echo $test[87402531]; //works
echo $test["87402531"]; //also works

var_dump($test);

这是输出:

This does not

Notice: Undefined offset: 1431739436 in ... on line ...

This works just fine

Notice: Undefined offset: 87402531 in ... on line ...

Notice: Undefined offset: 87402531 in ... on line ...

This should work now.
This should work now.

这是var转储:

array(3) {
  ["1229410050415660"]=>
    string(20) "This works just fine"
  ["87402531"]=>
    string(13) "This does not"
  [87402531]=>
    string(21) "This should work now."
}

这一直都有效。

echo $test[1229410050415660]; 

我怎样才能避免这种情况,或者如何从阵列中获得“这不是”?

我正在使用PHP 7.0.14。

谢谢!

0 个答案:

没有答案