This commit is contained in:
u2nyakim 2025-08-27 18:00:37 +08:00
parent f50b215653
commit e2d79ce1ef

View File

@ -145,18 +145,21 @@
*/
function formatJson(jsonString, indentSpaces = 2) {
//
if (typeof jsonString !== 'string') {
throw new Error('输入必须是字符串');
}
// JSONJavaScript
let parsedObj;
try {
parsedObj = JSON.parse(jsonString);
} catch (e) {
throw new Error('无效的JSON格式: ' + e.message);
if (typeof jsonString === 'string') {
// throw new Error('');
try {
parsedObj = JSON.parse(jsonString);
} catch (e) {
throw new Error('无效的JSON格式: ' + e.message);
}
}else{
parsedObj = jsonString;
}
//
function format(obj, depth) {
//