This my firebase database, now I want to iterate over each object inside the chat object, and I only want to check with the immediate child of chat that whether a particular email address is present or not. Please help me out with this.
Thank you.
"chat": {
"yasarbains03@gmail^com": {
"chatList": [
{
"author": "Sender",
"message": "Sample text message"
},
{
"author": "Sender",
"message": "Hey"
},
{
"author": "Sender",
"message": "Hi"
}
]
},
"yasarbains15@gmail^comyasarbains7@gmail^com": {
"chatList": [
{
"author": "Sender",
"message": "Sample text message"
},
{
"author": "Sender",
"message": "Hi"
},
{
"author": "Sender",
"message": "Hey"
}
]
},
"yasarbains7@gmail^com": {
"chatList": [
{
"author": "Sender",
"message": "Sample text message"
},
{
"author": "Receiver",
"message": "Hi"
},
{
"author": "Sender",
"message": "Hiii"
},
{
"author": "Sender",
"message": "Hello"
},
{
"author": "Sender",
"message": "hi"
},
{
"author": "Sender",
"message": "Hi"
},
{
"author": "Sender",
"message": "heyyy"
},
{
"author": "Sender",
"message": "Hii"
}
]
},
"yasarbains7@gmail^comyasarbains15@gmail^com": {
"chatList": [
{
"author": "Receiver",
"message": "Hey"
}
]
}
}
The chat object is of above form, and in this I want to search for, for example - yasarbains15@gmail^com, such that this email comes in a combination with some other email and this email is present first then the second email, like, “yasarbains15@gmail^comyasarbains7@gmail^com”.This can be done if I only read the email addresses and not the chatList inside email address. Is there any way to do that?
Try it… you can change the search term to whatever you like in my demo project.
Why do you have two email addresses joined together as a single property name?
Okay, let me check.
I am creating a chatting option in my app for customers and service providers, and in-order to store there chats, and fetch them for later display I am using two email addresses as unique key, so the chats will be stored as sender’s email + receiver’s email.
When I using my script in sampleJSON, and trying to print the child of chat object, I am getting null. Is there any way to read this form of JSON script?
Hello @yasarbains7mhf9pj
You are getting null because the “samepleJSON” variable doesn’t contain a JSON. A valid JSON should be inside these { }.