Problem Using Dictionaries

I don't understand what I am doing wrong and am looking for someone to point me in the right direction.

I am building an app that has a login screen. I have two Firebase DB's one stores the number of users, and the second stores the user data. I believe that I have created the user data correctly, and here is a screenshot of the data structure.


The blocks I used to store the data and the blocks for the login routine are here:

I am wanting to have the user enter two numbers to login, the first is a user number that is supposed to correspond to the index number of the user data. My first screenshot shows 3 users, user number one, two, and three. The second number entered by the user is a private PIN that they set.

I do store a data set called User_Number in the user data because I cant seem to get the list index number part to work. I would prefer to use the list index instead of storing User_Number in the data but either way, neither method works for me.

When I test, I do not get the ShowAlert messages never fire even if the data is wrong. Is my data is set up the way I want it to be? How can I make this work?

Why? You should organise your data in order to only use one database

Use Do It in companion mode to to see what data you are getting back from Firebase

use Do it to debug your blocks, see also tip 4 here App Inventor: How to Learn | Pura Vida Apps
see also Live Development, Testing, and Debugging Tools

Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

1 Like

Thank you for the tips. The Do It function is really going to help me. I found out what I believe the problem is, now off to see if I can fix it.

Thanks again!

Well I am still confused. The DO IT tool really helps but I guess I just don't understand some things still.

My new blocks to pull the data looks like this:

In my previous posts you can see where I define User_Data .. I use a Make a List block followed by a Make a Dictionary block (see example blocks in my first post).. is this a mistake? I would think the Make a List block would convert my dictionary to a list .. but I cannot use the List version of Look Up in Pairs block at all, because its not a list after all?

When I use the Get Value at Key block from Dictionaries it generates an error:

Lookup in pairs: the list ({"ChatName":"Rusty","PIMs":0,"PIN":"8462","Points":0,"Unused07":"7","Unused08":"8","Unused09":"9","Unused10":"10","Unused11":"11","Unused12":"12","Unused13":"13","Unused14":"14","Unused15":"15","Your Name":"Mabel"}) is not a well-formed list of pairs

This is the correct line of data so I know my INDEX routine works. I don't know why I don't have well formed pairs when I used the Key - Value blocks to create my data. I am trying to pull data using the key PIN .. what am I doing wrong?

Since this is a list of lists of sorts, is that my problem? There is no Key named PIN because its only looking at the top level of the data? I am so confused..

An ephemeral variable like value is gone before Do It can grab it.
Set a global variable debug_value to value when a new value arrives, and apply your Do It to a get global debug_value block to see its vapor trail.

1 Like

I am using some labels to display the Value when it comes in .. thats how I know my Indexing is working.

My question still stands, is my data a List or a Dictionary? Please see the third screenshot in my first post for blocks example.

May I asked did you saved data (json) directly in firebase or from your app ?

If I understand your question correctly, I saved the data from the app..

Wait .. the data is being saved to Firebase, is that what you are asking?

Do you have ShowListsAsJson ticked in your Screen1 properties in Designer ?

Please show the raw content in global User_Data

If I take your sample data it makes a list of pairs without the parantheses and after "decoding" the JSON from a string to a list


I did not have the ShowListAsJason checked but it is now..

I think this is what you are asking for..

[{"ChatName":"Stevie","JailTime":0,"PIMs":0,"PIN":"1234","Points":0,"Unused08":"8","Unused09":"9","Unused10":"10","Unused11":"11","Unused12":"12","Unused13":"13","Unused14":"14","Unused15":"15","UserNumber":2,"Your Name":"Timmy"}]

Now it returns a json list as string. Decode it and extract the first item of the list and you can access the list of pairs. (The .JsonTextDecode block can be found in the web component.)

There are blocks to apply that test.

P.S. I have seen dictionaries interpreted as lists on return from Firebase if their tags are integers.

1 Like

Thanks for the help, I am not familiar with that block and would not have known about it if you had not mentioned it.

That worked. I guess I need to read up on it, I don't want to just copy blocks, I want to understand what they do as well.

You are right. I completely forgot about those test blocks.

There are blocks to apply that test.

If you have worked with javascript you will probably have come across jsonParse and jsonStringify, the blocks jsonTextDecode and jsonObjectEncode do the same things respectively (their naming appears a bit backwards, but comes from the naming in java)

You will also find that, in many situations, list blocks will work with json dictionary objects and dictionary blocks will work with AI2 list objects.

Keep that ShowListsAsJson ticked. It is ticked by default when you open a new project.