Skip to content

Commit e1b606a

Browse files
committed
JSON解析失败时会显示原始内容
1 parent 372c251 commit e1b606a

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

  • src/main/java/com/github/balloonupdate/mcpatch/client/data

src/main/java/com/github/balloonupdate/mcpatch/client/data/IndexFile.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.balloonupdate.mcpatch.client.data;
22

3+
import com.github.balloonupdate.mcpatch.client.exceptions.McpatchBusinessException;
34
import com.github.balloonupdate.mcpatch.client.logging.Log;
45
import org.json.JSONArray;
56
import org.json.JSONObject;
@@ -17,10 +18,18 @@ public IndexFile() {
1718
versions = new ArrayList<>();
1819
}
1920

20-
public static IndexFile loadFromJson(String json) {
21+
public static IndexFile loadFromJson(String json) throws McpatchBusinessException {
2122
IndexFile indexFile = new IndexFile();
2223

23-
JSONArray array = new JSONArray(json);
24+
JSONArray array;
25+
try {
26+
array = new JSONArray(json);
27+
} catch (RuntimeException e) {
28+
throw new McpatchBusinessException("JSON解析失败,原始内容:\n"+json, e);
29+
// Log.error(e.toString());
30+
// Log.info("RawContent:\n" + json);
31+
// throw e;
32+
}
2433

2534
for (int i = 0; i < array.length(); i++) {
2635
JSONObject element = array.getJSONObject(i);

0 commit comments

Comments
 (0)