0
This is a. json file I created just to understand
{
"campo":
[
{"nome":"Lucas vidotti"}
]
}
I know that to read this value with jquery I need to do
$.getJSON
and manipulate by key, but I’m not able to read the json and play in html
For the structure, it would be something like this:
let val = $.getJSON; val.campo[0].nome;
– MarceloBoni
I don’t know how you get json, but if it’s in that structure, that’s the syntax for reading.
.
to access object key and[indice]
to access the array item.– MarceloBoni
You need to pass the file
.json
for the reading to be made– Dimitrius Lachi
I watched some tutorials and tried to do so $(Function(){ $("#mos"). click(Function(){ $.getJSON("main.json",Function(){ $("#span"). html(field.name); // so here I need to put the field[0]. name? }); }); });
– user95454
@Lucas depends on how you are working, with callback, synchronous, etc
– MarceloBoni
if a reply serves you mark it as accepted, see https://i.stack.Imgur.com/jx7Ts.png and why https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079. Enjoy a tour in https://answall.com/tour
– user60252