Value failed to convert to JSON

I tried to sum up six numbers that obtained from each six text boxes. But when I try on my phone, it popped up a message which is ‘Value failed to convert to JSON’. Can anyone help me? Thank you very much!

Works if you do it like this, but not if done directly or if output set to a variable…

1 Like

Thank you very much! It works!

Just be aware there is a subtle difference here.

The JSON spec as implemented in Java/Android limits numbers to IEEE 754 double floating point values, which have a min/max value of ±(2-2-52)*21023. Your calculation raises e to the power of 10000000000, which is much larger than than the max double value. Therefore, when we try to encode the number for storage in TinyDB the exception is thrown. App Inventor internally uses Scheme as its language, specifically Kawa scheme, which supports much larger numbers which is why App Inventor can support this calculation (see here for a discussion on the size of values).

In @TIMAI2’s solution, the number value is converted into a string by assigning it to the Label1.Text property. It’s the string representation of the number that gets written to the TinyDB. This generally shouldn’t be a problem since App Inventor attempts to coerce strings to numbers for numerical calculations, but you should be aware that the type technically has changed.


Thank you for the explanation, Evan :+1:

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