+ 2

API’s

I’m trying to learn how to make and use API’S. From this code I can understand most of it until the .explanation on line 30. can anyone explain why its there and what it does? cus i looked it up and no results are found https://code.sololearn.com/W3rRyN9RVM2b/?ref=app

13th Jun 2022, 11:16 PM
Junior
Junior - avatar
21 Réponses
+ 3
https://www.w3schools.com/whatis/whatis_json.asp
13th Jun 2022, 11:39 PM
Simon Sauter
Simon Sauter - avatar
+ 2
data is a JSON object. Its contents are accessed using dot notation. So data.explanation accesses the data in the explanation field of the JSON object.
13th Jun 2022, 11:30 PM
Simon Sauter
Simon Sauter - avatar
+ 2
JSON is a format for saving data. It's very simple and very popular. You should take a look at it.
13th Jun 2022, 11:38 PM
Simon Sauter
Simon Sauter - avatar
+ 2
The call to the API fetches a JSON object. This is often the case for data APIs. This object is then assigned to the data variable for further manipulation. https://www.digitalocean.com/community/tutorials/how-to-work-with-json-in-javascript
14th Jun 2022, 12:20 AM
Simon Sauter
Simon Sauter - avatar
+ 1
In the code three fields of the JSON object are accessed: explanation, title, and url.
14th Jun 2022, 12:13 AM
Simon Sauter
Simon Sauter - avatar
+ 1
So the JSON object looks probably something like this: {"explanation": "some text", "title": "some text", "url": "an image url"}
14th Jun 2022, 12:16 AM
Simon Sauter
Simon Sauter - avatar
0
ohh. so do i have to learn json?
13th Jun 2022, 11:36 PM
Junior
Junior - avatar
0
okay
13th Jun 2022, 11:38 PM
Junior
Junior - avatar
0
Okay so I just webt over the json stuff but i didnt see anything that has .explanation. or anything really like that
14th Jun 2022, 12:05 AM
Junior
Junior - avatar
0
mainly what i learned was stringify and parse and some other stuff.
14th Jun 2022, 12:13 AM
Junior
Junior - avatar
0
Ok, thanks. But why is that code ur showing not in his code? Is it in some url or something
14th Jun 2022, 12:17 AM
Junior
Junior - avatar
14th Jun 2022, 12:28 AM
Simon Sauter
Simon Sauter - avatar
0
oh interesting. i see. so exactly how can u see that data? I learned about .parse form recieving data from a web url. but how do u get it?
14th Jun 2022, 12:31 AM
Junior
Junior - avatar
0
did he write that?
14th Jun 2022, 12:33 AM
Junior
Junior - avatar
0
That's lines 27-28. With the API's url in line 23.
14th Jun 2022, 12:33 AM
Simon Sauter
Simon Sauter - avatar
0
Okay thank u
14th Jun 2022, 12:34 AM
Junior
Junior - avatar
0
You're welcome.
14th Jun 2022, 12:34 AM
Simon Sauter
Simon Sauter - avatar
0
wait. also one last thing. Do u have to parse? In w3schools they say when recieving information form a web url its stringified so it will say the values and stuff. so why didnt he parse?
14th Jun 2022, 12:35 AM
Junior
Junior - avatar
14th Jun 2022, 12:39 AM
Simon Sauter
Simon Sauter - avatar
0
hmm okay!
14th Jun 2022, 12:40 AM
Junior
Junior - avatar