mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-15 12:07:42 +00:00
Merge pull request #7611 from keymanapp/fix/android/json-obj-parser
fix(android/engine): Handle parsing empty JSONArray as JSONObject
This commit is contained in:
commit
ad58fa7f1a
1 changed files with 9 additions and 0 deletions
|
|
@ -16,6 +16,8 @@ import java.io.StringReader;
|
|||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
|
@ -43,6 +45,13 @@ public final class JSONParser {
|
|||
}
|
||||
jsonStr = strBuilder.toString();
|
||||
if (type == JSONObject.class) {
|
||||
String EMPTY_JSONARRAY_FORMATSTR = "^\\[\\](\\n)*$";
|
||||
Pattern pattern = Pattern.compile(EMPTY_JSONARRAY_FORMATSTR);
|
||||
Matcher matcher = pattern.matcher(jsonStr);
|
||||
if (matcher.matches()) {
|
||||
// Treat empty JSONArray as empty JSON Object. Issue #7564
|
||||
jsonStr = "{}";
|
||||
}
|
||||
obj = (T) new JSONObject(jsonStr);
|
||||
} else if (type == JSONArray.class) {
|
||||
obj = (T) new JSONArray(jsonStr);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue