javascript - Why does it need to convert the format to json when dividing information into several columns and storing it in localstorage?
世界只因有你
世界只因有你 2017-05-19 10:30:38
0
4
531


#This book says that to store information in several columns, you need to use json.
But why do I feel like I can just use objects directly instead of json?
I don’t understand why json is used. I hope dalao can answer:
Can I use objects? If not why?
Why use json? These three questions. Thanks

世界只因有你
世界只因有你

reply all(4)
仅有的幸福

Localstorage stores strings and cannot directly put objects into it

phpcn_u1582

It’s not entirely correct to say it’s json, it should be json in escaped string format.

Remember, local storage can only store strings.

过去多啦不再A梦

One thing you need to always pay attention to in the original MDN article is that all data will be converted into a string through its .toString method before being saved to any of the memories to be introduced below. So a normal object will be stored as "[object Object]", not the object itself or its JSON form. It is better and more common to use the JSON parsing and serialization methods provided by the browser itself to access objects.

过去多啦不再A梦

Is it difficult to open the browser and try it out

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!