Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将json对象解码到php数组时无法获取完整整数值_Php_Facebook Graph Api_Curl - Fatal编程技术网

将json对象解码到php数组时无法获取完整整数值

将json对象解码到php数组时无法获取完整整数值,php,facebook-graph-api,curl,Php,Facebook Graph Api,Curl,我在facebookapi上发送了一个curl请求,我得到了这个响应 '{ "id": "137392510101234", "email": "open_mhfgkal_user@tfbnw.net", "first_name": "Open", "last_name": "User", "link": "https://www.facebook.com/app_scoped_user_id/137392510108522/", "name":

我在facebookapi上发送了一个curl请求,我得到了这个响应

'{
    "id": "137392510101234",
    "email": "open_mhfgkal_user@tfbnw.net",
    "first_name": "Open",
    "last_name": "User",
    "link": "https://www.facebook.com/app_scoped_user_id/137392510108522/",
    "name": "Open Graph Test User"
}'
现在我正在尝试读取id的值。我使用了下面的代码

$jsonid='{
    "id": "137392510101234",
    "email": "open_mhfgkal_user@tfbnw.net",
    "first_name": "Open",
    "last_name": "User",
    "link": "https://www.facebook.com/app_scoped_user_id/137392510108522/",
    "name": "Open Graph Test User"
}';

 $jsonArrayToken = json_decode($jsonid,true);
 echo $jsonArrayToken['id'];
但我无法读取id的全部值。 我只得到前四位数字“1373”。 我要完整的id“137392510101234”


有什么错误吗?请建议我。

工作罚款检查如下:

评估链接:

问题可能在于代码中没有提供对象而不是数组的地方。您应该访问以下数据:

<?php
    $jsonid='{
        "id": "137392510108522",
        "email": "open_mhfgkal_user@tfbnw.net",
        "first_name": "Open",
        "last_name": "User",
        "link": "https://www.facebook.com/app_scoped_user_id/137392510108522/",
        "name": "Open Graph Test User"
    }';

    $arrayid = json_decode($jsonid); // json_decode provide an OBJECT, not an array
    $id = $arrayid->id;

    echo $id;
?>

我刚刚复制了您的代码添加了var\u导出,没有发现问题

<?php
header('content-type: text/plain');
$jsonid='{
    "id": "137392510108522",
    "email": "open_mhfgkal_user@tfbnw.net",
    "first_name": "Open",
    "last_name": "User",
    "link": "https://www.facebook.com/app_scoped_user_id/137392510108522/",
    "name": "Open Graph Test User"
}';

 $jsonArrayToken = json_decode($jsonid,true);
 echo $jsonArrayToken['id'] . "\n\n";
 var_export($jsonArrayToken);

?>


您的示例代码运行良好,因此问题一定出在其他地方。我在测试代码时得到了良好的值,您以后是否将该值转换到其他地方?在
JSON\u decode
中设置
JSON\u BIGINT\u AS\u STRING
选项,这将使它将所有可能溢出系统整数限制的大整数解析为字符串值,因此,不存在由于隐式转换为浮点值而导致精度损失的问题。这对我很有效。非常感谢您节省了我的时间,我在过去8小时中一直在这方面受挫。再次感谢。你是个了不起的人。
137392510108522

array (
  'id' => '137392510108522',
  'email' => 'open_mhfgkal_user@tfbnw.net',
  'first_name' => 'Open',
  'last_name' => 'User',
  'link' => 'https://www.facebook.com/app_scoped_user_id/137392510108522/',
  'name' => 'Open Graph Test User',
)