About strings and objects
1.localStorage can only save strings, if the object directly into the Localstorage, then directly save the string object
2. If you call Localstorage's GetItem ("carts") method, the information obtained is also a string
3.js and String conversions
JS Object----> string: var str=json.stringfy (JS object)
String----->js object: var obj=json.parse (string);
such as strings and objects
Class Person extends object{
String name;
}
Person P=new person (); This is a Java object, converted to a string, using the ToString method
In short, from the local to get the data is a string, first from the string to the JS object (array), the same, the end of the data to be converted into a string and then stored locally, the code is as follows:
var books=localstorage.getitem ("carts");//Get String
var bookarr=json.parse (books);
var s=json.stringify (Bookarr);
Localstorage.setitem ("carts", s);