这是我的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])); } }更多推荐
发布评论