Skip to content

Commit 0751e12

Browse files
author
Damian Staszewski
committed
API Now check content.
If content is Object using JSONObject, if content is Array using JSONArray, otherwise, content use String.
1 parent fc35ba5 commit 0751e12

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/main/java/pl/stachu540/util/API.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import com.sun.istack.internal.Nullable;
55
import org.apache.commons.io.IOUtils;
6+
import org.json.JSONArray;
67
import org.json.JSONObject;
78

89
import java.io.InputStream;
@@ -110,8 +111,9 @@ private void fillJSONObject(JSONObject jsonObject, boolean success, requestType
110111
data.put("responseCode", responseCode);
111112

112113
jsonObject.put("data", data);
113-
jsonObject.put("content", jsonContent);
114+
if (jsonContent.startsWith("{") && jsonContent.endsWith("}")) jsonObject.put("content", new JSONObject(jsonContent));
115+
else if (jsonContent.startsWith("[") && jsonContent.endsWith("]")) jsonObject.put("content", new JSONArray(jsonContent));
116+
else jsonObject.put("content", jsonContent);
114117
jsonObject.put("exception", exception);
115-
116118
}
117119
}

0 commit comments

Comments
 (0)