处理JSON对象异常

This commit is contained in:
aixianling
2023-03-01 18:10:08 +08:00
parent ebcfff03cc
commit c221ce8965
2 changed files with 12 additions and 3 deletions

View File

@@ -1,4 +1,11 @@
const checkJson = str => {
if (typeof str == 'object') {
try {
str = JSON.stringify(str)
} catch (e) {
return false
}
}
if (typeof str == 'string') {
try {
let obj = JSON.parse(str);