#How I can get String from an "json" URL?

23 messages · Page 1 of 1 (latest)

wintry vault
thin bladeBOT
#
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
  • Marked as resolved by OP
lament tree
#

What do you mean be “String”

#

Like the data when you put the link into a browser?

#

First, you will need to fetch the site. Which’ll return the json

await fetch(url)

Will fetch it

wintry vault
lament tree
#

Secondly, you’ll need to use the method .json(), which will return a promise of the json the site returns

#

If you give that a go and come back with any issues, I can help

wintry vault
lament tree
#

.json() is also a promise. So try wrapping either your fetch in a function, or just attach your fetch to a variable first, which I would say to do

#

const d = await fetch(url)

#

then if(d.ok) {
const json = await d.json()
}

#

The ok property just shows if the request was successful

wintry vault
lament tree
wintry vault
lament tree
#

bruh .json() is a method

wintry vault
lament tree
#

.json() not .json

#

It’s a method, not a property

wintry vault
#

omg

#

nvm

wintry vault