How to create nutrition app with ocr scanner?

You can see an example of proper JSON parsing (just one way to do it but a good way) here:


Many thanks @tatiang

I highly appreciate your praise to my work.


Thank you for all the help! I’m going to work on it and I’ll show you what I come up with in a couple of hours.

Should it be something like this?

Can someone please help me fix these errors, I need to finish this app today?

1 Like

You are using a variable carb and you have assigned it the object of the API response.

Then you try to compare this object with simple numbers. This will never yield true.

The other issue, you need to keep in mind that else if condition evaluation is progressive which means it will check the first condition and if it happens to be true then no more conditions will be checked or tested. However, if the first condition comes up false, the next else if will be tested and again the next condition will only be tested when the current condition is false.

The way you listed the condition in the code does not follow this role and therefore will not work properly.

1 Like

What should I replace for the object of the api response instead of the variable carbs?

1 Like

Also is this how I should keep my if/else blocks?

1 Like

Let’s do what they call it dry run.

Assume the number you have from your API is 19.

What will happen with the blocks?

The first block is testing if the number is greater than or equal 12.5 so this will be true. And the label Very health will have the text “Very healthy” showing on it.

Let’s see the next condition, is the number (19) greater than or equal18, the answer is yes and the label Somewhat healthy will show the text “Somewhat healthy” on it.

Let’s proceed to the third block, is the number less than or equal 19, the answer is no and the label will not get updated.

Now the app is confusing the user. It has two labels with text in them. One saying “Very healthy” and the other saying “Somewhat healthy”.

This is not good.

1 Like

I changed the if/else statements, but it still shows an error with the blocks. Are the get properties parsed wrong? Or is there another error?

You’ve written nutriments instead of nutrients.

1 Like

They called it “nutriments”.

1 Like

Sorry, my bad. Didn’t notice.

1 Like

That’s okay! Thanks for helping!

So basically, the food is healthy if the carbs are less than 12.5?

Yes, it is

OK, then you’ve done it the other way around. You’ve done
if app variable carbs ≥ 12.5

but it’s actually
if app variable carbs 12.5

Also, the food is unhealthy if the carbs are more than 19, right?
If so, then you need to change the symbols like in my last post.

I changed the signs for both of them but it still says that there is an error with the blocks.

1 Like

Can you share a screenshot of that error?