
Amy S.
asked 08/02/20URGENT: Problems with API in C# ASP.NET Core
I am doing an ASP.NET Core Website and have to show the list of all countries with their travel advisory scores in a table. I can't display the data using a Travel Advisory API. Each country is a separate key and are different classes when I paste the JSON as classes.
How can I call each country's class (eg. AU
) and display the data under the country using a loop? The problem is that there are too many countries so I hope to use a loop for this. As you can see in the code below, I can only show one country at a time as each country is a different class.
Basic API Endpoint: https://www.travel-advisory.info/api
Optional Parameter: https://www.travel-advisory.info/api?countrycode=AU
(restrict the result list to a single country)
My Code:
Model: https://controlc.com/da48a2be
Controller: https://controlc.com/51d938c7
1 Expert Answer

Michael C. answered 09/16/20
Lead Software Engineer Specializing in ASP.NET
So if you are allowed to use the Base API, you can do this by utilizing a dictionary. The Data object returned is just a string, object dictionary. Here is an example of using the base api and printing the names to a view.
Here is an example of the model, view, and controller.
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Michael C.
Is there a requirement you can't use the Base API to get all the countries or you just can't figure out how to make that work?09/16/20