2
Hello, I get a json on this request template
{
"alunos":[
{
"ID":"1",
"Nome":"Pedro",
},
{
"ID":"2",
"Nome":"Lucas",
},
{
"ID":"3",
"Nome":"Joana",
}
]
}
I would like a good example of how to store it in a local variable, for later use, array would be a good choice ?
Look, I don’t know if I understood your question correctly, but it wouldn’t be good to use for example: var obj = JSON.parse(jsonString); ???
– DiegoSantos
It’s a good way?
– Stan
Actually, I don’t see another one! This way, you already turn the string into an object and do what you want with it. Do you understand? Only make this change: var obj = JSON.parse(jsonString) || {}; Because if it cannot convert, it returns an empty obj...
– DiegoSantos
What is the concrete doubt you have ? Or what are you unable to do with this information ? What @Diegosantos said already solves the problem and stores the information in an object that is ideal in almost all cases.
– Isac
to save in obj I always have to write obj, or I can put something else ?
– Stan
That’s just the variable name. You can have any name you want.
– Isac
Okay thanks, doubt settled
– Stan