Json data works on some sites not on others same code

Hello im trying to learn inventor and I've been following some tutorials online. Currently im working on pullung json files off of websites. I was originally making a weather app however the site will not return data. So, I have been troubleshooting trying to figure it out and I found another site to use, and it actually returned the data so what's the difference and why can i not pull from the one site, but I can from the other?
The site I want to use to pull data - https://forecast.weather.gov/MapClick.php?lat=40.4406&lon=-79.9958&FcstType=json

The site that will actually work and send json data - https://transport.data.gouv.fr/gbfs/vcub/station_information.json

I notice the format for the information on each page is different not sure if its something to do with that or what here is my code blocks in inventor. I had more functionality in the program but I backed up and made it simpler in order to solve the no return data on one site problem. Thank you for any help!

I suggest you to First try to get the key and then get values.. as you said both are in different json struture.

This site says access denied if i use it as web url where as the second one do give json response


When I put it in my browser this comes up. Im not familiar with key yet im able to look through the json on the 2nd site by indexing the list though. I was trying to use the weather site to update a weather app based on my location but it doesnt return any response from my web call. Do some websites not respond or allow you to pull it?

pls see the blocks for the second web address.. you can take the whole details from the obtained json and make following list. From this list you can take any values, equally from any list

(Note: If you use webviewr you will get result from website1)

The NWS site requires a user-agent Authentication. See API Web Service

Here is a way to Authenticate your app's use of the NWS (USA National Weather Service) forecasts in json format (allows you to access the weather forecast).

This code

allows you to download the json from the NWS.

When you do it (on a real device (it wouldn't work using the stock emulator)) it should look like this

Now experiment :slight_smile:

You may have to adjust the url to get the exact response you hope for.

This also works....

image

You could also use a webviewer and some runJavascript....
(courtesy @Juan_Antonio HERE)

fetch('\
https://forecast.weather.gov/MapClick.php?lat=40.4406&lon=-79.9958&FcstType=json\
').then( function(response) {\
response.text().then(function(data) {AppInventor.setWebViewString("" + data.toString()); });\
})\
.catch(function(err) {AppInventor.setWebViewString("Error");});
1 Like

(added to FAQ)