Home > Mobile >  how to read json data with async storage
how to read json data with async storage

Time:04-26

const [myotp_value,setMyotp_value] = useState();
const demojsondata = {
   'otp_value': '00112233', 
   'student_id': '111111'
 }
await AsyncStorage.setItem("Otp_details", JSON.stringify(demojsondata));

await AsyncStorage.getItem("Otp_details").then((value)=> console.log(value));

 await AsyncStorage.getItem("@Otp_details").then((value)=>setMyotp_value(value));

console.log(myotp_value);

if(userOtp==cmpOtp){
  console.log('user otp verified');
}

i want to compare this otp_value to user input. please community tell me how to do that.

CodePudding user response:

const data = {
  name: "Foo",
  surname: "Bar"
};

// save json data to async storage as string
await AsyncStorage.setItem("key", JSON.stringify(data));

// read json data from async storage
AsyncStorage.getItem("key").then(JSON.parse).then(value => {
  console.log(value.name); // Foo
  console.log(value.surname); // Bar
});
  • Related