Home > Backend Development > PHP Tutorial > javascript - Why does the data stored in the front end need to be converted to a string?

javascript - Why does the data stored in the front end need to be converted to a string?

WBOY
Release: 2016-08-04 09:20:29
Original
996 people have browsed it

Storage userData data

<code class="javascript">localstorage.setItem("userData",JSON.stringify(userData));</code>
Copy after login
Copy after login

Why is it so troublesome to convert data into stringsand then take it out and then convert it into an object?
Storing the object directly, isn’t it okay to take out the object and use it directly?

Reply content:

Storage userData data

<code class="javascript">localstorage.setItem("userData",JSON.stringify(userData));</code>
Copy after login
Copy after login

Why is it so troublesome to convert data into stringsand then take it out and then convert it into an object?
Storing the object directly, isn’t it okay to take out the object and use it directly?

For some data with abstract data structures, such as binary trees and objects, it is not linear compared to arrays, so when the TCP protocol transmits data, it needs to be converted into something similar to an array, and then inserted into the network stream (similar to a pipeline ) inside, and then restore the original shape on the other side (just like when transporting a bed, you need to disassemble it first, and then put the bed boards back together at the destination).

https://developer.mozilla.org/en-US/docs/Web/API/Storage/setItem

Function signature not allowed

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template