Adding Data in Firebase Database - android

I am migrating to Firebase to help me retrieve my data. My question is how can I format my Firebase Database data like the JSON below. How can I specify objects like the JSON below?
[
{
"DoctorsName": "DR.LUTAAYA HUZAIFAH IDRIS",
"HealthCentreName": "Mulago",
"Specialisation": "Dentist",
"Information": "am genious",
"photo": "huzaifah.jpg",
"WorkingHours": "8:00am - 3:00pm",
"PhoneNumber": "0704594180",
"Email": "huxaiphaeridris#gmail.com"
},
{
"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": "wabulembo#gmail.com"
},
{
"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": "bukijauha#gmail.com"
},
{
"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": "sekitoleko#gmail.com"
},
{
"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": "makhoba#gmail.com"
},
{
"DoctorsName": "DR.Sako Banabus",
"HealthCentreName": "Nakasero Hospital",
"Specialisation": "Dentist",
"Information": null,
"photo": "kamanzi.jpg",
"WorkingHours": "7:00pm - 3:00am",
"PhoneNumber": "0754369696",
"Email": "sw#gmail.com"
},
{
"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": "kamanziabubakar75#gmail.com"
}
]

You can write pretty much any JSON you'd like directly to Firebase. For ease of retrieval though, you'd need to figure out some sort of schema. I'd recommend something like the following:
doctors
<docotrId>
- doctorId
- doctorName
- specialisation
- information
- photo
- phone
- email
- #healthCenter
healthCenters
<healthCenterId>
- centerId
- name
- #doctors[]
specialisationDoctors
<specialisationName>
<doctorId>
The first thing you need to do is map your data to this schema. You can create POJO classes, Maps, or even JSON formatted strings.
Then push your mapped data using setValue() on the appropriate nodes. Make sure to read the documentation for more information.
You might also want to check out a Firebase object mapper I'm working on called Firebomb (shameless plug). The Android version will be coming soon.
Finally retrieve data by using the appropriate Firebase event listeners.

Related

Google Pay for UK - administrativeArea is empty

Integrated the GooglePay and able to launch GPay Sheet successfully. Prefilled with test card and test UK address. On clicking "continue", in response the administrativeArea is blank - always for other UK address also.
{ ... "shippingAddress": { "address3": "", "sortingCode": "", "address2": "", "countryCode": "GB", "address1": "6 Pancras Square", "postalCode": "N1C 4AG", "name": "UK User", "locality": "London", "administrativeArea": "" } }
I could find other similarity also while adding address the state/county option is not present for UK (as in below screenshot).

replace &qoute: with " " in string in android

i am using volley request and in response i am getting folloiwng
[{
"body":
"Jazz Your Offer se abhi *303# milain aur enjoy karaen poora din 50 JazzWarid minutes siraf Rs 10 bama tax mai",
"address":"JAZZ",
"
date":"November 12, 2019","
time":"Tuesday, 10:49:45 AM"
}]
What i want , i want clear json array like
[
{
"body": "Alhumdulilah.. ap snao",
"address": "+92XXXXXXXXXX",
"date": "October 09, 2019",
"time": "Wednesday, 8:56:23 PM"
},
{
"body": "Alhumdulilah.. ap snao",
"address": "+923XXXXXXXXX",
"date": "October 09, 2019",
"time": "Wednesday, 8:56:23 PM"
}
]
how can i achieve in android ?
Try using HtmlCompat.fromHtml to overcome this problem
String formattedResponse = HtmlCompat.fromHtml(
response,
HtmlCompat.FROM_HTML_MODE_LEGACY).toString();
You can use
jsonString.replace(""", " ")
to replace occurencies of """ with spaces.

How to get a particular object from JSON array [Android] [duplicate]

This question already has answers here:
How to parse JSON in Kotlin?
(17 answers)
Closed 3 years ago.
I have a response json like this,
[{
"userId": 1,
"id": 1,
"title": "quidem molestiae enim"
},
{
"userId": 2,
"id": 2,
"title": "sunt qui excepturi placeat culpa"
},
{
"userId": 3,
"id": 3,
"title": "omnis laborum odio"
}]
I want to show detail from userId = 3, I wasn't provided an endpoint to get detail. So I want to get detail from this endpoint.
in App:
I've shown the data for dashboard (using recyclerview/list)
After that, I want to go to detail from one data that I selected.
Case: I'm using 1 endpoint (like above)
JSONArray jsonArray = (JSONArray) JSON.parse(str);
Map map = jsonArray.stream().map( obj -> {JSONObject jsonobject = (JSONObject) obj;return jsonobject;}).collect(Collectors.toMap(obj->obj.getIntValue("userId"),obj->obj.toJSONString()));
System.out.println(map.get(3));
the start point of json must always be a jsonObject not jsonArray. head to your backend developer and ask him or her to put your jsonArray inside a jsonObject.
{
"docs":[{
"userId": 1,
"id": 1,
"title": "quidem molestiae enim"
},
{
"userId": 2,
"id": 2,
"title": "sunt qui excepturi placeat culpa"
},
{
"userId": 3,
"id": 3,
"title": "omnis laborum odio"
}]
}

How do you find a user's twitter id from a user's twitter username in Android

In my android app, I want users to be able to enter a twitter username and from there the twitter app launches on the entered username's page. I did some research and found out the link needed to open the twitter app from another app is twitter://user?user_id=id_num I was wondering if there is a way to get the user's twitter id from a twitter username in Android so I can make this happen. Any help would be greatly appreciated, thank you.
You should read through the Twitter API, in particular the section about user lookups
Edit: Links updated to current Twitter API docs though answer remains targeted at API v1.1 as when asked.
That particular request has optional fields to search by id or screen_name and will return a list of matches which you can parse for user ids. So you can search by screen_name and read the response to get an id.
The request you are (were) looking for is:
GET https://api.twitter.com/1/users/lookup.json?screen_name=somename
The provided response in the API examples is (was):
[
{
"name": "Twitter API",
"profile_sidebar_border_color": "87bc44",
"profile_background_tile": false,
"profile_sidebar_fill_color": "e0ff92",
"location": "San Francisco, CA",
"profile_image_url": "http://a3.twimg.com/profile_images/689684365/api_normal.png",
"created_at": "Wed May 23 06:01:13 +0000 2007",
"profile_link_color": "0000ff",
"favourites_count": 2,
"url": "http://apiwiki.twitter.com",
"contributors_enabled": true,
"utc_offset": -28800,
"id": 6253282,
"profile_use_background_image": true,
"profile_text_color": "000000",
"protected": false,
"followers_count": 160752,
"lang": "en",
"verified": true,
"profile_background_color": "c1dfee",
"geo_enabled": true,
"notifications": false,
"description": "The Real Twitter API. I tweet about API changes, service issues and appily answer questions about Twitter and our API. Don't get an answer? It's on my website.",
"time_zone": "Pacific Time (US & Canada)",
"friends_count": 19,
"statuses_count": 1858,
"profile_background_image_url": "http://a3.twimg.com/profile_background_images/59931895/twitterapi-background-new.png",
"status": {
"coordinates": null,
"favorited": false,
"created_at": "Tue Jun 22 16:53:28 +0000 2010",
"truncated": false,
"text": "#Demonicpagan possible some part of your signature generation is incorrect & fails for real reasons.. follow up on the list if you suspect",
"contributors": null,
"id": 16783999399,
"geo": null,
"in_reply_to_user_id": 6339722,
"place": null,
"source": "TweetDeck",
"in_reply_to_screen_name": "Demonicpagan",
"in_reply_to_status_id": 16781827477
},
"screen_name": "twitterapi",
"following": false
},
{
"name": "Twitter",
"profile_sidebar_border_color": "EEEEEE",
"profile_background_tile": false,
"profile_sidebar_fill_color": "F6F6F6",
"location": "San Francisco, CA",
"profile_image_url": "http://a1.twimg.com/profile_images/878669694/twitter_bird_normal.jpg",
"created_at": "Tue Feb 20 14:35:54 +0000 2007",
"profile_link_color": "038543",
"favourites_count": 2,
"url": "http://twitter.com",
"contributors_enabled": true,
"utc_offset": -28800,
"id": 783214,
"profile_use_background_image": true,
"profile_text_color": "333333",
"protected": false,
"followers_count": 3305606,
"lang": "en",
"verified": true,
"profile_background_color": "ACDED6",
"geo_enabled": true,
"notifications": false,
"description": "Always wondering what's happening. ",
"time_zone": "Pacific Time (US & Canada)",
"friends_count": 257,
"statuses_count": 774,
"profile_background_image_url": "http://s.twimg.com/a/1276896641/images/themes/theme18/bg.gif",
"status": {
"coordinates": null,
"favorited": false,
"created_at": "Tue Jun 22 16:40:19 +0000 2010",
"truncated": false,
"text": "9 cool things to do with your Twitter account (via #pastemagazine) http://example.com",
"contributors": [
16739704
],
"id": 16783169544,
"geo": null,
"in_reply_to_user_id": null,
"place": null,
"source": "web",
"in_reply_to_screen_name": null,
"in_reply_to_status_id": null
},
"screen_name": "twitter",
"following": false
}
]
So you can access the id from the results by parsing that JSON response for the "id" field.
Note however that the returned is a JSON array of results and not just a single definitive answer. You will need to work out yourself which is the correct one (order is not guaranteed either so do not assume the first entry is the most likely).
Also worth noting is that even though this is documented as returning 'id' and an integer value, the current preferred usage of ids is to supply 'id_str' and a string representation of the integer. This is due to inconsistencies in how various platforms handle and limit integers. So even if you receive 'id' you should use 'id_str' for future interactions.
Assuming you have a bearer token from the Twitter Developer Platform, you can get the id for a given username with the Twitter API v2 users lookup endpoint.
So for example, if I send an authorized GET request to
https://api.twitter.com/2/users/by?usernames=TwitterDev,TwitterAPI
Response:
{
"data": [
{
"id": "2244994945",
"name": "Twitter Dev",
"username": "TwitterDev"
},
{
"id": "6253282",
"name": "Twitter API",
"username": "TwitterAPI"
}
]
}
Python Code Example:
import requests
bearer_token = '<YOUR_TWITTER_BEARER_TOKEN_HERE>'
headers = {"Authorization": f"Bearer {bearer_token}"}
params = {"usernames": "TwitterDev,TwitterAPI"}
url = "https://api.twitter.com/2/users/by"
# Get list of twitter follows
r = requests.get(url, params=params, headers=headers, timeout=20)
if r.status_code != 200:
raise Exception(
"Request returned an error: {} {}".format(
r.status_code, r.text
)
)
json_response = r.json()
for u in json_response['data']:
username = u['username']
id = u['id']
print(f"The user id for {username} is {id}")
Output:
The user id for TwitterDev is 2244994945
The user id for TwitterAPI is 6253282
See also:
Twitter Developer Platform - Users lookup
Twitter APIv2 sample code - get_users_with_bearer_token.py
TweeterID - Twitter ID and username converter

What format is this data stored as? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I'd like to parse the following information and would like to identify the format that it is in?
{
"interval": {
"id": 0,
"starts_at": 1317851120683,
"ends_at": 1317851374436
},
"identifier": "2021902",
"category": "music",
"original_category": "",
"buy_link": "http://click.linksynergy.com/fs-bin/stat?id=6z5Z0DsswBo&offerid=162397&type=3&subid=0&tmpid=3664&RD_PARM1=http%253A%252F%252Fitunes.apple.com%252Fca%252Falbum%252Foh-my-what-a-fine-day%252Fid360945836%253Fi%253D360945883%2526uo%253D4%2526partnerId%253D30",
"title": "Oh My, What A Fine Day",
"artist": "Behind Sapphire",
"album": "Behind Sapphire",
"publisher": "Behind Sapphire",
"itunes_song_id": "360945883",
"album_art": {
"src": "http://www.streamon.fm/player/getAlbumArt.php?u=http://a4.mzstatic.com/us/r30/Music/fc/73/1d/mzi.briyobdw.170x170-75.jpg",
"width": 170,
"height": 170,
"alt": "Behind Sapphire",
"link": ""
},
"next_song": "",
"next_buy_link": "",
"next_album_art": {
"src": "",
"width": 0,
"height": 0,
"alt": "",
"link": ""
},
"banner": {
"src": "",
"width": 0,
"height": 0,
"alt": "",
"link": ""
}
}
JSON.
See this: http://developer.android.com/reference/org/json/package-summary.html
JSON, or JavaScript Object Notation, is a lightweight text-based open standard designed for human-readable data interchange.
You can refer to wikipedia, and you could get some useful information
JSON. In this web http://www.json.org/ you can found a extensive index of libs for parse this information.

Categories

Resources