catch 省略参数
javascript
function isValidJSON(text) {
try {
JSON.parse(text)
return true
} catch {
return false
}
}
const json = '{ "key1": "value1", "key2": "value2" }'
console.log(isValidJSON(json)) // true