📌  相关文章
📜  javascript 检查字符串是否可解析 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:47.604000             🧑  作者: Mango

代码示例3
function isValidJSONString(str) {
    try {
        JSON.parse(str);
    } catch (e) {
        return false;
    }
    return true;
}
//usage
var personJSONString = '{"first_name":"Tony","last_name":"Hawk","age":31}';
if(isValidJSONString(personJSONString)){
 //cool we are valid, lets parse
 var person= JSON.parse(personJSONString);
}