Load a json list in JS

Asked

Viewed 42 times

0

I would like to upload a list of my JSON file to use in my Javascript , to use the.table() console with the provided information ,

This is my Javascript code :

fetch("infos.json") // especifique o caminho
.then(response => response.json())
.then(json => console.table(json))

And this is JSON’s :


{"Jogadores":[{"Jogador":"Player1","Pontuação":"15 pnts"},{"Jogador":"Player2","Pontuação":"12,3 pnts"},{"Jogador":"Player3","Pontuação":"11,6 pnts"},{"Jogador":"Player4","Pontuação":"11,2 pnts"}]}

ScreenShot Do Erro No console e a visualização do json no Firefox

  • What error is generating?

  • Sorry I went to see you have a character error in JSON !

  • I’m new to the script

  • JSON error : Syntaxerror: JSON.parse: Unexpected non-whitespace Character after JSON data at line 1 column 10 of the JSON data .

  • Add the error directly to the question.

1 answer

2


Just run a fetch

fetch("dados.json") // especifique o caminho
.then(response => response.json())
.then(json => console.table(json))

@EDIT now that I have seen the syntax error. Anyway, it is suggested to use fetch :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.