1. JSON.parse(text[, reviver])
text 必需 有效的json字符串
reviver 可选 函数
2. 举栗子
1) 只有第一个参数
let objStr = ‘{"name": "lqw","age": 23,"sex": "female"}‘;
console.log(JSON.parse(objStr));
结果:
{name: "lqw", age: 23, sex: "female"}
2)第二个参数存在
let objStr = ‘{"name": "lqw","age": 23,"sex": "female"}‘; console.log(JSON.parse(objStr, function (key, value) { if (typeof value === ‘string‘) { return value.toUpperCase(); } return value; })); 结果: {name: "LQW", age: 23, sex: "FEMALE"}
原文:https://www.cnblogs.com/lqw007/p/9618420.html