1、JSON字符串转化JSON对象
let JSONString = '{"userName": "半晨", "password": 20211117}';
console.log(JSON.parse(JSONString));
// {userName: "半晨", password: 20211117}
2、JSON对象转化JSON字符串
let JSONObject = {
userName: '半晨', password: '20211117' };
console.log(JSON.stringify(JSONObject));
// {"userName":"半晨","password":"20211117"}
3、JSON字符串的输出美化
let beautify = [{
userName: '半晨', password: '20211117' }];
console.log(JSON.stringify(beautify, undefined, 2));
// [
// {
// "userName": "半晨",
// "password": "20211117"
// }
// ]