Browse Source

fix(Student): 处理学生作业内容解析时的潜在错误

添加try-catch块以捕获JSON解析可能出现的错误,防止程序因无效内容而中断
SanHQin 2 weeks ago
parent
commit
ff809cec17
1 changed files with 9 additions and 3 deletions
  1. 9 3
      src/views/Student/components/answerTheResult.vue

+ 9 - 3
src/views/Student/components/answerTheResult.vue

@@ -265,9 +265,15 @@ const choiceQuestionList = () => {
     });
     (props.workArray ?? []).forEach(
       (studentWork: any, studentIndex: number) => {
-        const _studentContent: any = JSON.parse(
-          decodeURIComponent(studentWork.content)
-        ).testJson
+        let _studentContent: any = []
+        try {
+          _studentContent = JSON.parse( 
+            decodeURIComponent(studentWork.content)
+          ).testJson
+        }
+        catch (error) {
+          console.log(error)
+        }
         // let _studentContentCorrection = []
         // console.log(_workData)
         // console.log(_studentContent)