2021年5月4日星期二

how to work with json elements in react native

Sending data into the API with the following code

    signIn: async (email, senha) =>{      try{          const req = await fetch ( `${BASE_API}/Auth/login.php`,{               method: 'POST',               headers:{ Accept: 'application/json', 'Content-Type': 'application/json' },               body: JSON.stringify({email: email, senha: senha})           });             const json = await req.json();           console.log(json);           return json;       }        catch(error){           console.error(error);       }  }  

returns the following json that is being trown into console.

Array [ Object { "user_avatar": "path", "user_celular": "00912341234", "user_email": "test@gmail.com", "user_id": "6", "user_mesa": "0", "user_nome": "Marcos", "user_senha": "testtest", "user_since": "2021-04-28", "user_sobrenome": "da Silva", "user_tipo": "0", }, ]

how can I extract data from this json? for example: alert(json.user_nome)

https://stackoverflow.com/questions/67394947/how-to-work-with-json-elements-in-react-native May 05, 2021 at 11:48AM

没有评论:

发表评论