0
こんにちは私は自分のコードを共有しています 問題はそれがエラーなしで動作していますが、 "例外JsonExceptionは、サーバー内にあります。対応するtryステートメントの異なる環境でJSONExceptionがスローされることはありません
「JSONExceptionをスローする」という宣言を次の2つのメソッドに追加すると問題は解決されますが、実際はそうしたくありません。その理由は何でしょうか?
private JSONArray convertStringToJsonArray(String source)throws JSONException {
return new JSONArray(source);
}
private JSONObject getElementIndexAt(JSONArray jsonArray, int index)throws JSONException {
return jsonArray.getJSONObject(index);
}
public class JsonModifier {
public String getElementIndexAt(String source, int index){
String output;
try
{
JSONArray jsonArray = convertStringToJsonArray(source);
JSONObject jsonObject = getElementIndexAt(jsonArray, index);
output = convertJsonToString(jsonObject);
}
catch(JSONException ex)
{
log.error("Page not found, exception: " + ex.getMessage());
output = "Page not found, exception: " + ex.getMessage();
}
return output;
}
private JSONArray convertStringToJsonArray(String source) {
return new JSONArray(source);
}
private JSONObject getElementIndexAt(JSONArray jsonArray, int index) {
return jsonArray.getJSONObject(index);
}
private String convertJsonToString(JSONObject jsonObject){
return jsonObject.toString();
}
}