【问题标题】:JSON does not show id from DBJSON 不显示来自数据库的 id
【发布时间】:2021-03-24 16:21:54
【问题描述】:

我使用 PHP CURL 在 JSON 文件中从我的 firebase 数据库返回数据,但它没有显示记录的 ID

我的代码:

<?php
$url="https://******.firebaseio.com/a_info.json";
$ch= curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 
$response=curl_exec($ch);
curl_close($ch);
print_r($response);
?> 

【问题讨论】:

    标签: php json firebase curl firebase-realtime-database


    【解决方案1】:

    这是因为 Firebase 将您的顺序数字键解释为数组索引,并将结果作为 JSON 数组返回。

    如果您想阻止 Firebase 执行此转换,请确保您的键不是序列号,例如通过在它们前面加上一个固定的短字符串:

    "a_info": {
      "key0": {...},
      "key1": {...},
      ...
    }
    }
    

    另见:Best Practices: Arrays in Firebase

    【讨论】:

      猜你喜欢
      • 2021-11-28
      • 2018-05-09
      • 1970-01-01
      • 1970-01-01
      • 2021-08-28
      • 1970-01-01
      • 2013-07-30
      • 2013-02-25
      相关资源
      最近更新 更多