Dictionary keys seem to turn into strings when stored into tinyDB

Not sure if this is a bug or a feature but the simple test below shows a phenomena which does not make sense to me. The first alert shows 'true', naturally. However, when stored and retrieved from tinyDB, the numeric key does not exists anymore and the second alert shows 'false'. The third alert shows 'true' again. Usually comparison between numeric values and strings should work just fine in app inventor but this time it doesn't. Am I doing something wrong, is this a bug or just a feature that I need to cope with? I'm sorry if this issue exists already. I couldn't find any discussions related to this.

image

Returns as a dictionary for me:

Try again using number as a key

No issues with number as text, or number as number when setting a key.

Please show me what you did to test that. The way I do it in my example, the problem exists.

Kind of a simpler case but same problem. Key '2000' cannot be found when using a number as a reference. First alert false, the next two true.

image

I see your problem now.

In Dictionaries/JSON ALL keys MUST be placed inside double quotes. Therefore if you send a number as a key, it will be put in double quotes.

You can overcome this by using a join block

image

image

Alright. Thank you! So the answer to my question is that this is a feature :slight_smile: I just need to wrap the dictionary functions into own functions or use 'join' block every time I access dicts just to make sure that the key is found no matter the type.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.