3
{
"recordsets": [
[
{
"IdUsuario": 5152490,
"strNome": "Roberto ",
"IdPapel": 1
},
{
"IdUsuario": 5152490,
"strNome": "Roberto ",
"IdPapel": 3000001
}
]
]
I am trying to return to the customer only his permissions (Idpapel), however, I am not getting.
Follows the code that executes the query and brings as a result the JSON presented:
function verify(query, res, user) {
sql.connect(dbConfig, (err) => {
if (err) {
console.log("Error while connecting database :- " + err);
res.sendStatus(403);
sql.close();
} else {
var request = new sql.Request();
request.query(query, (err, result) => {
if (err) {
console.log("Error while querying database :- " + err);
res.sendStatus(403);
sql.close();
} else {
res.send(result);
sql.close();
}
});
}
});
}
Any hint?
Thank you!
You want to send an array containing each Idpapel this is it?
– João Pedro Henrique
Actually I want to send a JSON to the other side, containing only the papers.
– Matheus Bernardi
Right, so in case you want to send that array of users over there?
– João Pedro Henrique
I would like to submit the name and all the papers of this user. This example json presents the same user several times, however, changing only Idpapel. But if I know how to send only Idpapel, I can send the name. It turns out I can’t get a specific element of the array, from the error.
– Matheus Bernardi
I got what you want. This JSON is what is saved in the result variable there of the correct SQL query?
– João Pedro Henrique
That’s right @Joãopedrohenrique . I’m taking this json from mssql by Node.
– Matheus Bernardi
Okay, I’ll write you an answer then
– João Pedro Henrique
Just one more question, it’s coming back JSON already decoded, correct?
– João Pedro Henrique
It’s returning the JSON the same way I put it in the example. When ordering from the API, it brings this JSON
– Matheus Bernardi
cashed. But this function that makes the call in the database... The result variable is a string with a JSON or it has already decoded the JSON?
– João Pedro Henrique
I can’t say... I even believe that might be why I’m not getting what I want
– Matheus Bernardi