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 garbled code problem is as follows: The reaso...
The installation information on the Internet is u...
From the backend to the front end, what a tragedy....
Table of contents Preface Main implementation cod...
This article shares the specific code of JS to ac...
This article shares the specific code of vue elem...
Open DREAMWEAVER and create a new HTML. . Propert...
The reason is this I wanted to deploy a mocker pl...
Nowadays, whether you are on the sofa at home or ...
Floating ads are a very common form of advertisin...
Preface Crond is a scheduled execution tool under...
This article shares the specific code of Vue to i...
Table of contents Preface Problem: Large file cop...
background First, let me explain the background. ...
Look at the code: Copy code The code is as follows...