search

Home  >  Q&A  >  body text

javascript - Why does it need to convert the format to json when dividing information into several columns and storing it in localstorage?


#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

世界只因有你世界只因有你2804 days ago565

reply all(4)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-19 10:32:38

    Localstorage stores strings and cannot directly put objects into it

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-19 10:32:38

    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.

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-19 10:32:38

    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.

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-19 10:32:38

    Is it difficult to open the browser and try it out

    reply
    0
  • Cancelreply