How to convert a JSON string into a JSON object?JSON.parse(str) JSON is a built-in object in JavaScript, which provides methods for converting JSON objects to strings and vice versa; Here comes the problem. I understand the principle but it still reports an error!This is one of my JSON files, which contains some defined JSON test data; This is the core code; This is an error message; Why is the error reported?Because there is a space at the beginning of my json file. That's it. OK, modify the code and test Use trim to remove extra spaces at the beginning ok, passed! Nodejs parses JSON dataIn nodejs, you don’t need to import the json2.js file like in js, you can directly operate the JSON object Convert string to JSONvar str = "{ ' a ' : ' 1 ' , ' b ' : ' 2 ' }"; var json = JSON.parse(str); JSON to stringvar json = { a : ' 1 ', b : ' 2' }; var str = JSON.stringify(json); The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Ubuntu 18.04 obtains root permissions and logs in as root user
>>: Import csv file into mysql using navicat
The meta tag is used to define file information an...
Table of contents 1. Plugins 2. Interlude 3. Impl...
Table of contents Component Infrastructure Purpos...
This article shares the specific code for JavaScr...
Overview Databases generally execute multiple tra...
A Multi-Select is a UI element that lists all opt...
<br />With the increase of bandwidth, there ...
Table of contents js calling method Android 1.js ...
1. About Registry The official Docker hub is a go...
CSS 3 animation example - dynamic effect of Tab b...
Table of contents Preface VMware clone virtual ma...
There are two ways to disable form submission in ...
Written in front There are two ways to upgrade My...
In the previous blog, we talked about using Nginx...
How to uninstall MySQL database under Linux? The ...