Need Help With Api

https://api.dictionaryapi.dev/api/v2/entries/en_US/USA
Hi , this is my api and this is the code is used
image
But my app is not returning USA in the alert , it returns null

First, you need to check for errors and you also need to check if the status is 200 or not. Check out @tatiang’s video on API handling. Also, what do you see when you run the app?

i checked the response it returns whatever there is i am supposed to receive.
But i cant understand how to get the word property

[
{
word: "USA",
phonetics: [
{
text: "/ˌju ˌɛs ˈeɪ/",
audio: "https://lex-audio.useremarkable.com/mp3/usa_us_1.mp3"
}
],
meanings: [
{
partOfSpeech: "abbreviation",
definitions: [
{
definition: "United States of America."
},
{
definition: "United States Army."
}
]
}
]
}
]

I get this when i just check the response
image
probably because there is a square bracket in the result this error maybe caused , can you tell how to handle this?

I have a small doubt: since you already have USA written in the URL, that means you already know the word, why are you using an API to get the same thing?

no , that is just an example , i have a random word generator and that will be used to generate a word. Also , i actually needed the audio property but thought the word property would be easier to fetch

1 Like

Oh, ok. May I ask which random word generator you are suing, since I’m looking for one myself?

https://random-word-api.herokuapp.com/all
thunkable code:


https://random-word-api.herokuapp.com/home
Also , this api is not owned by me nor am i promoting it :grinning:

1 Like

Thank you very much! I just pasted the response from the dictionary API into a json formatter, and it says that the JSON is invalid. Can you do this:
when you set the web API’s url, paste it into an input, and add a wait 4 seconds block. In that time, copy the response and paste it here. I want to see what response you are getting, not just the sample data.

1 Like

this is what i get in thunkable
[{“word”:“USA”,“phonetics”:[{“text”:"/ˌju ˌɛs ˈeɪ/",“audio”:“https://lex-audio.useremarkable.com/mp3/usa_us_1.mp3"}],“meanings”:[{“partOfSpeech”:“abbreviation”,“definitions”:[{“definition”:"United States of America.”},{“definition”:“United States Army.”}]}]}]

1 Like

Cool, let me paste it and tell you what I find.

Thanks , you can use this link too https://api.dictionaryapi.dev/api/v2/entries/en_US/USA

1 Like

Thanks!

OK, so there’s something very weird going on.
When I try to paste your first response in a JSON formatter, it says Bad String, and doesn’t format it. When I paste the response from the link, it formats it correctly.

That’s strange

1 Like

Aha! In the first response, you have curved quotation marks: “ ”. They’re supposed to be straight, like this: " ". Before parsing, use a replace block to replace all the curved quotation marks with the straight ones.

Where to do this exactly?

The problem is that your API returns invalid JSON. JSON cannot contain comments (lines that start with //).

Where are those lines in the random word generator or word detail finder?

Actually, I was wrong. Thunkable seems to handle those comments okay in the response.

This works:

You have to take the first item of the list before getting the property “word” because the JSON response has an array ([ ] brackets).

1 Like

You can see this is the case if you paste the response to something like this:

https://random-word-api.herokuapp.com/word?number=10

Into this site and click Tree Viewer:

2 Likes