Я использую HTTP-шифрование.если шифрование ложно, веб-сервис отправляет простой JSON со значением false, а если шифрование верно, я отправляю массив JSON с данными.
test () - это метод, который "пробует" API с наборомлогина: пароль.
У меня проблемы с использованием JSON, который я получаю (JSONException: конец ввода с символом 0)
Вот код всего кода (я не думаю, что весь этот кодбудет служить, но ...) и сразу после кода, который создает исключение JSON:
private void test(String l, String p) {
Log.v("MWW", "test de DialogBoxAuth");
TextView erreur = (TextView) findViewById(R.id.erreurtext);
String url = Main.app_preferences.getString("domain", "domain")+"api.php/1.0/authenticate";
WebService webService = new WebService(url);
Log.v("MWW", ".:" + url);
// creation d'un MAP
Map<String, String> params = new HashMap<String, String>();
// Réponse JSON via le webservice avec les parametres
response = webService.webGet("", params, l, p);
HttpEntity entity = response.getEntity();
Log.v("MWW", "entity = " + response.getEntity().toString());
if (entity != null) {
try {
ret = EntityUtils.toString(response.getEntity());
Log.v("MWW", "ret = " + ret.toString());
} catch (IOException e) {
Log.e("Groshie:", e.getMessage());
}
try {
Log.v("MWW", "01");
JSONArray childs = new JSONArray(ret);
Log.v("MWW", "02");
// affiche le JSON
Log.v("MWW", "-->" + childs.toString());
Log.v("MWW", "03");
for (int j = 0; j < childs.length(); j++) {
JSONObject childNodeJSON = childs.getJSONObject(j);
// On récupère les données une par une et on les set dans la classe adéquate
String ok = "ok";
if (childNodeJSON.getString("status").equals(ok)) {
MajLoginPassword(l, p);
dismiss();
break;
} else {
erreur.setText("Login ou password incorrect");
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}else{
erreur.setText("Vérifiez votre connexion à internet");
}
}
Код, обеспечивающий исключение:
if (entity != null) {
try {
ret = EntityUtils.toString(response.getEntity());
Log.v("MWW", "ret = " + ret.toString());
} catch (IOException e) {
Log.e("Groshie:", e.getMessage());
}
try {
Log.v("MWW", "01");
JSONArray childs = new JSONArray(ret);
Log.v("MWW", "02");
Я вижу Logcat "01«но не« 02 », поэтому« org.Json.JSONException: конец ввода в символе 0 »ошибка исходит из этой строки:
JSONArray childs = new JSONArray(ret);
Где и почему возникает это исключение?
Я могу решить эту проблему в одиночку ... Я не понимаю этого!Большое спасибо, чтобы прочитать мою проблему, Клем '
Хорошо, большое спасибо!Прочитав ваши комментарии, я обновил код:
try {
Log.v("MMW", "01 : ret = " + ret.toString());
//JSONArray childs = new JSONArray(ret);
JSONObject childs = new JSONObject(ret);
Log.v("MMW", "02");
// affiche le JSON
Log.v("MMW", "-->" + childs.toString());
Log.v("MMW", "03");
for (int j = 0; j < childs.length(); j++) {
//JSONObject childNodeJSON = childs.getJSONObject(j);
JSONObject childNodeJSON = childs;
// On récupère les données une par une et on les set dans la classe adéquate
String ok = "ok";
if (childNodeJSON.getString("status").equals(ok)) {
MajLoginPassword(l, p);
dismiss();
break;
} else {
erreur.setText("Login ou password incorrect");
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}else{
erreur.setText("Vérifiez votre connexion à internet");
}
Но есть новое исключение:
JSONException : end of input at character 0 of ...
И logcat говорит
ret =
01 : ret =