I want to use the data from JSON.stringify that I save locally from async storage, so I can manage them locally (like user data for login)
I already save it to AsyncStorage
componentDidMount = async () => {
fetch('My_url', {
method: 'GET'
})
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson);
this.setState({
data: responseJson
})
})
.catch((error) => {
console.error(error);
});
}
saveData = async () => {
try {
await AsyncStorage.setItem('user', JSON.stringify(this.state.data));
Alert.alert('Saved', 'Successful');
} catch (error) {
Alert.alert('Error', 'There was an error.')
}
this is the JSON
0
username "admin2"
password "*****"
access "1"
name "dwi"
phone_number "087613721"
email "**@****.com"
score null
status "0"
1
username "admin3"
password "***"
access "1"
name "Satria"
phone_number "****"
email "*****3@*****.com"
score null
status "0"
and I try to get the value using this, but can't show anything in node console.log, it said "unidentified" (i just using press button on this)
displayData = async ()=>{
try{
let user = await AsyncStorage.getItem('user');
let parsed = JSON.parse(user);
console.log(parsed.email);
}
catch(error){
alert(error)
}
}
can some JSON parser output use like to be database function? like for login so we can log in and check the data user from json.parser that I store in the data using async storage? or output some data that we want to be used like in where statement in the SQL ?