Storage data:
sessionStorage.setItem("loginInfo",JSON.stringify(bdata));
Get data
var loginObj=JSON.parse(sessionStorage.getItem('loginInfo'));
In web development, session storage is often used to store data, so it is not difficult to store a single string data variable
var str = 'This is a string';
sessionStorage.setItem('param',str);
Get sessionstorage
var item = sessionStorage.getItem('param');
console.log(item);
However, sessionstorage can only store string type data, and can’t directly store array types and JSON objects. If there is a need, what should I do?It’s very simple.
First, the JSON object is passed through JSON.stringify () code> method is converted to a string and stored in sessionstorage
var obj = {
"name": "Tom",
"age": 12,
"gender": "man"
};
sessionStorage.setItem('jsonParams',JSON.stringify(obj));
And then through JSON.parse () code> method to convert the string to JSON format
var data = JSON.parse(sessionStorage.getItem('jsonParams'));
console.log(data);
Read More:
- Parsing the exception of storing JSON string in cookie
- JSON data format net.sf.json .JSONException: A JSONObject text must begin with ‘{‘ at character 1 of Error:(f…
- Pandas read_ Error in json() valueerror: training data
- Error reading JSON file: json.decoder.JSONDecodeError : Extra data: line 6 column 2 (char 1329)
- Off line data storage and upload scheme
- Rselenium packet capture chain home network (Part 2: data storage and fault tolerance management)
- R reads JSON data
- 【ipfs-api】npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
- [jQuery] jQuery operates on JSON strings or JSON objects
- Nebula queries data and reports an error. Storage error: part: XX error: e_ RPC_ FAILURE(-3).
- failed to lazily initialize a collection of role: ……, no session or session was closed
- session_ start(): open(SESSION_ FILE, O_ Rdwr)) failed: processing of permission denied (13)
- To solve the problem of failed to load: data in HTML5 game running rmmv locally/ actors.json problem
- User defined profile in vscode settings.json And default configuration defaultSettings.json
- Postman returns to the data window and displays the JSON format by default
- Django + jQuery get data in the form + Ajax send data
- A solution to automatically convert special characters into Unicode when taking out data from MySQL and encapsulating it into JSON
- Python json.dumps () json.dump The difference between ()
- Solution to 1030 got error 28 from storage engine in MySQL
- Tensorflow reported an error when using session module: attributeerror: module ‘tensorflow’ has no attribute ‘session’, which has been solved