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
Preface: Fully encapsulating a functional module ...
What is LNMP: Linux+Nginx+Mysql+(php-fpm,php-mysq...
Why is it stuck? There is a premise that must be ...
This article uses examples to describe how to bac...
MySQL database is widely used, especially for JAV...
I wrote a test program before, in which adding and...
definition Calcite can unify Sql by parsing Sql i...
Table of contents 1. Boolean 2. Expression 3. Mul...
1. Use pseudo-classes to display half of the Bord...
Servermanager startup connection database error R...
【Problem Analysis】 We can use the chown command. ...
How to check the status of Linux firewall 1. Basi...
Table of contents 1. Array.at() 2. Array.copyWith...
today select * from table name where to_days(time...
Table of contents Easy to use Create a project vu...