I have this Firebase database structure that I am trying to import into my app. How do I get the first element “van1” without explicitly calling van1 but usin in list get #1? I have googled for several hours now and I’m still at a lost. I trying to get the Brand name of van1.
Can anyone point me in the right direction on how to access this JSON object. It’s not a array of objects. I think that’s where I have the problem. I need the JSON to be [{},{}] and not {{},{}}
Thanks for the fast reply. However lets say that I will not have an idea about the “van1” key. I know VEHICLES exists but inside VEHICLES are items which have unique ids… How can I get the first item in the list of items in VEHICLES?
So one way would be to call vehicles and get the list and then use the get#1fromlist block in the list drawer. you would have to parse the list but thats not super hard.
No, you have to clean the data up that is going into the list. When you get the data back from firebase, it will have ALL the data from vehicles. You have to remove the pieces of data you dont want. I’ll see if I can make an example for you.
OK, here ya go. Try this out and it should give you a list of the FIRST items and then you can call each item as you wish. Also you are replacing the characters with blank boxes, so basically deleting them so it is easier to work with the data.
I use a label and a list viewer so I can see the json I am working with. It helps me figure out where I need to split my data. I am sure there is a better way to do this but thats how I found works for me.
Your solution gave me the right path to follow but holy cow that’s a lot of work just to get a list. Is there really no other way to sort of iterate through the JSON object?
Since you want to make apps/code anything, u should not look for any shortcuts. Sometimes code will be < 1000 lines / 1000 blocks. You need to have a habit of dealing with large no. of blocks…
We are currently working on adding a block that will allow you to get all the properties of an object. So in your case you could get a list that would look like ["van1", "van2", "van3", ...]. Then you could iterate over that list and plug those values into the 'get property' block.
Another thing to note is that if you are in control of that Firebase DB then you could presumably store the VEHICLES as a list rather than as an object. Then you could access it the way that you want to (i.e., by simple index). If you are in control of that Firebase DB, can you share the blocks that you use to store the data? If we see that, we could probably suggest how to change it so that it stores the vehicles as a list.
I solved my problem by using simple keys in my Firebase DB. Using predictive keys like van1,van2, van3 and so on I can use substrings to get the data I need. And yes I have full control on the DB. Its not ideal but it will have to do for now.
I need someone who knows about API and JSON. I want to select a CITY from list 1 and after show the towns of the selected city in list 2. I couldn’t solve my problem. Can someone check what is wrong?