2
In Javascript I’m getting a JSON like this:
function checaEad(){
var urlEad = 'http://urljason.json';
$.getJSON(urlEad, function(data) {
console.log(data);
});
}
He returns it to me:
{"user_cpf":"111.111.111-11","user_name":"NOME","matriculas":{
"357847":{"mat_id":357847,"id_curso":2129,"concluido":true},
"358696":{"mat_id":358696,"id_curso":4738,"concluido":true},
"362953":{"mat_id":362953,"id_curso":5041,"concluido":false}
}}
Now I’m unable to handle this array.
I need to check if inside the array that returned to me exists the id_curso = xxxx
, if any, check whether concluido = true
.
I tried something like this:
data.includes('5041');
But it says that the token is invalid, it is not for me to treat the same if it is a simple array? Because it works like this:
[1, 2, 3].includes(2); // true
Understand the JSON syntax is fundamental to know how to manipulate it. Basically, if it is bounded by
{
and}
is an object. To be an array, the delimiter must be[
and]
.– hkotsubo
And complementing tbm, the object you will access its properties using a
.
and in the array usually via a index.– LeAndrade
your check is whether the conclusion is
== true
or is to change the conclusion to=true
??? was in that doubt?– novic