I'm starting in React Native, I had no problems until I started doing HTTP requests. I'm using this function:
async getJSON(url, parameters){
try{
//check if URL isn't empty
if(url.length == 0)
return false;
//construct HTTP parameters
var params = '';
for (var key in parameters) {
if(params.length)
params += "&";
params += key + "=" + encodeURIComponent(parameters[key]);
}
//doing request
const response = await fetch('${url}${params}');
let body = await response.json();
return body;
}catch(err){
console.error(err);
return false;
}
}
So I got Promisse to follow:
Promise {_40: 1, _65: 0, _55: null, _72: Handler}
v
_40:1
_55:{success: false, msg: "segredo não informado"}
_65:1
_72:null
__proto__:Object
This JSON in object _55 is what I want to get, could simply access and get it, but that would not be correct (it goes that number changes, haha).
So I adapted the code below from from that post , and entered the code before the return body; of the first code.
Promise.resolve(body).then(function(value) {
console.log(value); //aqui deu log do JSON!
body = value; // essa atribuição não funcionou, por algum motivo
});
The above assignment should pass the JSON to the body , but in the end returned the Promise again ... I tried putting a await before Promise.resolve but nothing changed .
I looked at the documentation , I will search then-> gt; then schema. I do not know what else to do.