When decoding JSON, zeros are converted to 'false'

A student of mine is working on a project that involves decoding weather data in JSON format from open-meteo.com. An example could be a list of values denoting, hour by hour, how many millimeters of rain will fall.

When the weather is dry, 0 millimeters of rain will fall, and so the list often contains a lot of zeros. Apparently, when using JsonTextDecodeWithDictionaries from the Web component, each zero is converted to the boolean value false, which causes some problems when further processing the data.

It's easy enough to get around (we've created a little procedure that loops through a list and converts the other way), but it would be nicer not to have to.

Show your blocks and result

Not able to replicate....

image

Apparently the problem only happens when running the app on an iPhone via the companion app. On Android it works as expected (the 0s remain 0s).

Blocks:

Result:

The URL used is: https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41&hourly=temperature_2m,rain,snow_depth
If you wish to peruse the data in its raw form.

I changed the category, may get more attention from MIT that way....

Thanks.

Thanks, that's a nicer way to get the relevant values. Not really relevant to the main problem, though, unless I'm missing something?

Or like this??

Edited

If you scroll up and read the previous comments, you'll see that I've since figured out that the problem only occurs on IOS.

1 Like

Thank you for the report. I implemented the original code and recall there being some problems because iOS represents both booleans and integers as NSNumber with 0/1 and we had problems differentiating which was which. I'll see if I can revisit that code but at the moment I'm tied up in other parts of iOS.

Thanks, and no big hurry on my account - as I mentioned, the workaround is simple enough and will do for my student's project. :slight_smile:

@tayacan Would you be willing to install the beta version of MIT App Inventor from Apple TestFlight? I'm trying a very simple demo app decoding JSON and it appears to be working correctly but I'm wondering if it works correctly for your use case.