Hey, I need a bit of help with Apis

Since like 3 moths ago I'm trying and doing experiments with apis, I alredy post a few of questions I can get solutios but there are some things that I still don't understand. Now I'm with an weather api, I'm don't understanding how to read it. I'm tryng to get specific information by dictonarys keys and lists. I will show you by some pictures and go explaining the problem.


here's the code, I tryed the logic with another api and it work, so I think that is more in the way I read the apis.

Here's the api look, I read it like look in observations for imperial and next look for temp.
It finds observations but it doesn't find imperial and temp. I think that it's because the imperial and temp infomarion aren't show with [ ].
Would it be that it's another element in the list that i'm not seeing? Does It has a solution? Could you help me?
Thank you a lot :sparkling_heart::sparkling_heart:

Search the community for "weather". This has been asked many times.

1 Like

The trick to reading complex JSON is to work your way in from the outside, one level at a time.
If it's '{', you need to select by key.
If it's '[', you need to select by list item number.

Use a global dictionary to grab what you selected, one global per level, and to feed it to the next level of selection.

Your levels are

  • "observations"
  • 1
  • "imperial"
  • "temp"

for temperature, and

  • "observations"
  • 1
  • "humidity"

for humidity.

1 Like

thanks you a lot, I'm going to try it !!!

Hi, I also created an app using the openweather API and it was a pain at first because I did not know how to print debug codes. However, MIT app inventor allows you to run certain portions/blocks individually and see what string/value it returns by right-clicking the blocks and then pressing the Do It option. After implementing the right blocks, you should run them individually to make sure they are returning what you expect and adjust accordingly.

1 Like

If you find or setup right block, pls send here, it help many learner. :sparkling_heart:

Arun

1 Like

Thanks You very much, I'm going to try in that way.

Maybe this could be of help. For decoding complex json paths I always use (obvious)

3 Likes

(added to FAQ)

1 Like

thank you a lot :sparkling_heart::sparkling_heart:

Ok, Thanks You a lot for all your help, I would love to share with you how it's working the app now. All your replies were helpful. Now I'm going to share all the progress.
First of all I put the json on the Json Path Finder https://jsonpathfinder.com/ that @Luc_Volders shared, trying to understand more the file, next step was putting all togheter in the app, I used the logic that @ABG shared, put a 1 on the emply spaces.
@changminbark also help a lot, giving us tips of how to check that is all correct and a lot of thanks to @German_Skena and @Ramon .
Thank you to all of you for helping me with this issue.
This is the code and a bit of explanations of how does it works:


Ok, here you can see all the code coment and all the code without coments, heres the explanation:
First of all you need to create the url from where you are going to get all the information for you dictonarys, In my case I'm ussing two diferrents apis, one to get the stations id and another to get the climate conditions.
But, How do I get that information?
First of all I create an global variable for each data that I need, next I say to set that variable value to the value of a key world in the dictonary (make sure that you're using the get value at key path in case of needing to use list), in the case of needing the information of a element that is into another element, you have to use the make list block, here you put the name of how is that information show on the JSON document,
Next you only show it, you can make all the changes that you need to use that information later.

What is next?
I will try to see how to compare the information of an list with another list to select the correct station id for the user.
Also, I'm doing a code part to analice all the climate information and get the wildfires risk.

If you know how to answer any of these questions, you can comment. If you don't understand any part of the code or how I parse it, you can comment on that too!

Thank you a lot. :sparkling_heart::sparkling_heart::sparkling_heart:

1 Like

Thanks @Chiara_Angelina_Cata for your nice explanation, but image is not clear, You can provide drive link or other source for this nice explanation image.
or you can download block with showing comments.
:sparkling_heart:

Ok, I will upload each part individually because It doesn't allow me to download all the blocks with comments!




Imagen de WhatsApp 2024-04-17 a las 20.38.48_c6ab6f17



you can open each picture in a new tab for more information !

Remind me, what was the question?