The sessionStorage saved object becomes "[object Object]"?

var aa = {a:1,b:{c:2}}
sessionStorage.setItem("aa",aa)
sessionStorage.getItem("aa")
"[object Object]"

when you use sessionStorage to save an object, you can"t get a value, but print it out and find it becomes "[object Object]". What"s the reason?

Sep.24,2021

before saving the data, JSON.stringify () turn the string. Just because you save the object directly, the system uses qiang to zhi to transfer the string for you, that is, [object Object] .


var aa = {a:1,b:{c:2}};
sessionStorage.setItem('aa',JSON.stringify(aa));
bbb = JSON.parse(sessionStorage.getItem('aa'));
console.log(bbb);
The

object is converted to an object when it is first converted to json acquisition.


convert to a json string before saving, and then switch back to


localStorage and sessionStorage can only save strings, and will automatically call the object's toString method

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e3f88e-44834.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e3f88e-44834.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?