How to get a data from an array of arrays. react-native

0

Good morning, could anyone help me with react-native ??? The codes below and my doubts are below

componentDidMount() {
return fetch('http://portal.ema.net.br/api/getprocedimentospublicos', {
method: 'POST',
})
.then(response => response.json())
.then(dados => {
this.setState(
{
isLoading: false,
dados,
},
function() {}

);
})
.catch(error => {
console.error(error);
});
}

this fetch () takes a JSON like this:

{
"1": {
"TIPOPROCEDIMENTO": "Humanas",
"DESCRICAO": "Trabalhe%20com%20a%20Ema",

},
"2": {
"TIPOPROCEDIMENTO": "Uniema",
"DESCRICAO": "Solicita%E7%E3o%20de%20usu%E1rio%20AVE",
}

I mean in my STATE:

dados:{
"1": {
"TIPOPROCEDIMENTO": "Humanas",
"DESCRICAO": "Trabalhe%20com%20a%20Ema",

},
"2": {
"TIPOPROCEDIMENTO": "Uniema",
"DESCRICAO": "Solicita%E7%E3o%20de%20usu%E1rio%20AVE",
}

But I can not get this data with a simple "this.state.dados.1.TIPOPROCEDIMENTO"

So basically this is my question, how do I retrieve this data?

    
asked by anonymous 21.12.2018 / 14:52

1 answer

1

The answer to your problem is quite simple, just change the way you were doing:

this.state.dados.1.TIPOPROCEDIMENTO

By:

this.state.dados['1']['TIPOPROCEDIMENTO']

Test sample

    
21.12.2018 / 15:36