ting.yin 3 年之前
父節點
當前提交
7592d354a6
共有 1 個文件被更改,包括 18 次插入0 次删除
  1. 18 0
      stmms-web/src/main/java/cn/com/qmth/stmms/admin/utils/StudentJsonUtils.java

+ 18 - 0
stmms-web/src/main/java/cn/com/qmth/stmms/admin/utils/StudentJsonUtils.java

@@ -1,5 +1,10 @@
 package cn.com.qmth.stmms.admin.utils;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -8,6 +13,8 @@ import net.sf.json.JSONObject;
 
 import org.apache.commons.lang.StringUtils;
 
+import com.google.common.io.ByteStreams;
+
 public class StudentJsonUtils {
 
     public static final String ANSWER_SPLIT = ",";
@@ -36,6 +43,10 @@ public class StudentJsonUtils {
                 }
             } else if (answerObject instanceof Boolean) {
                 answer = answerJson.getBoolean("answer") ? "A" : "B";
+            } else if (answerObject instanceof JSONObject) {
+                if (((JSONObject) answerObject).isNullObject()) {
+                    answer = "#";
+                }
             }
             if (StringUtils.isNotBlank(answer)) {
                 list.add(answer);
@@ -43,4 +54,11 @@ public class StudentJsonUtils {
         }
         return StringUtils.join(list, ANSWER_SPLIT);
     }
+
+    public static void main(String[] args) throws UnsupportedEncodingException, FileNotFoundException, IOException {
+        File file = new File("/Users/ting.yin/Downloads/10128279.json");
+        String text = new String(ByteStreams.toByteArray(new FileInputStream(file)), "UTF-8");
+        String s = toAnswers(text);
+        System.out.println(s);
+    }
 }