包含数组的Firebase JSON数据(Firebase JSON data consisting arrays)

编程入门 行业动态 更新时间:2024-10-25 20:18:39
包含数组的Firebase JSON数据(Firebase JSON data consisting arrays)

这是我的firebase数据库。 当我导出这个数据库的JSON时,它给我以下JSON数据: -

{ "app1": { "app-icon": "some-icon", "app-name": "AmazingApp", "feature-id": 1, "image-list": { "image1": { "image-display-time": 20, "image-name": "Name", "image-sequence": 1, "music-file": "some mp3 file" }, "image2": { "image-display-time": 25, "image-name": "Name", "image-sequence": 2, "music-file": "some mp3 file" } }, "image-time-enabled": false } }

这里image-list是一个数组,但据我所知firebase不支持数组,因此没有[ ]表示数组。 因此,如果我将这个JSON数据提供给任何第三方使用,他们就无法使用这些数据,因为它们不能遍历节点image-list的子节点,因为它在技术上不是一个数组(尽管它是一个数组) )。

如何使用这样的JSON数据?

注意:第三方使用javascript并且不会直接访问firebase数据库,而是只使用来自纯文本的json。

This is my firebase database. When I export the JSON of this database it gives me the following JSON data:-

{ "app1": { "app-icon": "some-icon", "app-name": "AmazingApp", "feature-id": 1, "image-list": { "image1": { "image-display-time": 20, "image-name": "Name", "image-sequence": 1, "music-file": "some mp3 file" }, "image2": { "image-display-time": 25, "image-name": "Name", "image-sequence": 2, "music-file": "some mp3 file" } }, "image-time-enabled": false } }

Here image-list is a array but from what I know firebase does not support arrays, hence there are no [ ] which denotes a array. So if I give this JSON data to any third party to consume they are not able to consume this data since they cannot loop over the children of the node image-list as it is technically not an array(though it is meant to be a array).

How do I get to work with such a JSON data?

NOTE : The third party uses javascript and won't be accessing the firebase database directly instead they would just consume json coming from a plain text.

最满意答案

他们可以使用下面的for-in循环来获取对象。

for (var key in image-list) { if (image-list.hasOwnProperty(key)) { console.log(key + " -> " + JSON.stringify(image-list[key])); } }

They can use the for-in loop like below to get the objects.

for (var key in image-list) { if (image-list.hasOwnProperty(key)) { console.log(key + " -> " + JSON.stringify(image-list[key])); } }

更多推荐

本文发布于:2023-04-27 14:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1327207.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   数据   Firebase   arrays   JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!