2016-09-17 195 views
1

我迁移到火力帮我找回我的数据添加数据。我的问题是,如何格式化我的Firebase数据库数据,如下面的JSON。我怎样才能指定像下面的JSON对象?在火力地堡数据库

[ 
    { 
    "DoctorsName": "DR.LUTAAYA HUZAIFAH IDRIS", 
    "HealthCentreName": "Mulago", 
    "Specialisation": "Dentist", 
    "Information": "am genious", 
    "photo": "huzaifah.jpg", 
    "WorkingHours": "8:00am - 3:00pm", 
    "PhoneNumber": "0704594180", 
    "Email": "[email protected]" 
    }, 
    { 
    "DoctorsName": "DR. G. WABULEMBO", 
    "HealthCentreName": "Kibuli", 
    "Specialisation": "Opthalmologist", 
    "Information": " is a consultant Opthalmologist with over 25 years experience in Canada and Uganda.", 
    "photo": "wabulembo.jpg", 
    "WorkingHours": "8:00am - 12:00pm", 
    "PhoneNumber": "0756478923", 
    "Email": "[email protected]" 
    }, 
    { 
    "DoctorsName": "DR. BUKIRWA JAUHARAH", 
    "HealthCentreName": "Kibuli", 
    "Specialisation": "Urologist", 
    "Information": "Shes a Urologist , she has an experience of 7 years in Kibuli Hospital , and she studied in the United States Of America University", 
    "photo": "jauharah.jpg", 
    "WorkingHours": "10:00am - 4:00pm", 
    "PhoneNumber": "0706081457", 
    "Email": "[email protected]" 
    }, 
    { 
    "DoctorsName": "DR. R. SEKITOLEKO", 
    "HealthCentreName": "Nakasero Hospital", 
    "Specialisation": "General Physician", 
    "Information": " is consultant physician with over 33 years of experience in Berlin and Hamburg (Germany) and Mulago Hospital (Uganda). He also practised as a consultant with WHO (2001-2003).", 
    "photo": "sekitoleko.jpg", 
    "WorkingHours": "12:00am - 7:00pm", 
    "PhoneNumber": "0765633667", 
    "Email": "[email protected]" 
    }, 
    { 
    "DoctorsName": "DR. A. MAKHOBA ", 
    "HealthCentreName": "Nakasero Hospital", 
    "Specialisation": "Cardiologist", 
    "Information": "is a consultant cardiologist,. He has practised for more than 20 years in Illinois and Wisconsin (USA) and for over two years in Uganda, at the Uganda Heart Institute and Nakasero Hospital.", 
    "photo": "makhoba.jpg", 
    "WorkingHours": "8:00am- 4:00pm", 
    "PhoneNumber": "0765453636", 
    "Email": "[email protected]" 
    }, 
    { 
    "DoctorsName": "DR.Sako Banabus", 
    "HealthCentreName": "Nakasero Hospital", 
    "Specialisation": "Dentist", 
    "Information": null, 
    "photo": "kamanzi.jpg", 
    "WorkingHours": "7:00pm - 3:00am", 
    "PhoneNumber": "0754369696", 
    "Email": "[email protected]" 
    }, 
    { 
    "DoctorsName": "DR. KAMANZI ABUBAKAR", 
    "HealthCentreName": "Mengo Hosiptal", 
    "Specialisation": "Neurosurgeon", 
    "Information": "Hes a Neurosurgeon, he has an experience of 20 years in Mengo Hospital , he studied in the Carlifornia University", 
    "photo": "kamanzi.jpg", 
    "WorkingHours": "7:00pm - 3:00am", 
    "PhoneNumber": "07003014850", 
    "Email": "[email protected]" 
    } 
] 

回答

1

你可以直接写几乎任何JSON到Firebase。为了便于检索,你需要弄清楚某种模式。我建议如下所示:

doctors 
    <docotrId> 
    - doctorId 
    - doctorName 
    - specialisation 
    - information 
    - photo 
    - phone 
    - email 
    - @healthCenter 
healthCenters 
    <healthCenterId> 
    - centerId 
    - name 
    - @doctors[] 
specialisationDoctors 
    <specialisationName> 
    <doctorId> 

您需要做的第一件事就是将数据映射到此架构。你可以创建POJO类,地图,甚至是JSON格式的字符串。

然后使用适当的节点上setValue()把你映射的数据。请务必阅读documentation以获取更多信息。

你可能也想看看一个火力地堡对象映射我的工作称为Firebomb(无耻插头)。 Android版即将推出。

最后通过使用适当Firebase event listeners检索数据。

+0

感谢@艾伦·K,但它仍然是混乱,可以使之更加清晰和易于 –

+0

@Lutaaya不知道我是否可以把它更加明确给出你的问题是如何普遍。你不明白什么?如果您正在寻找要编写的特定代码,也许您可​​以先告诉我您尝试实现此目的的平台(Android,Web,Java服务器等)? –

+0

好@Alan,特别是我在谈论Android的,我说的困惑,因为,它的我很难检索到的Android。我试图实现我在Firebase中发布的JSON格式,以便轻松检索它。 –