I’m using HTTP encryption. if the encryption is false, webservice send a simple JSON with the value false and if the encryption is right, I send JSON array with datas.
test() is the method that “try” the api with a set of login:password.
I have trouble using the JSON that I receive (JSONException : End of input at character 0 )
Here’s the entiere code (I don’t think that this whole code will serve but…) and just after the code that make a JSON Exception :
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");
}
}
The code that provide the Exception :
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");
I can see the Logcat “01” but not the “02”, so “org.Json.JSONException : End of input at character 0” the error is coming from this line :
JSONArray childs = new JSONArray(ret);
Where and Why this Exception is leaved?
I can fix this problem alone… I dont understand it !
MANY thanks to read my problem, Clem’
Ok, many thanks ! After reading your comments, I’ve updated the code :
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");
}
But there is a new exception:
JSONException : end of input at character 0 of ...
And the logcat says
ret =
01 : ret =
Have you tried changing
to
I had similar issues when trying to use a JSONArray initially. Since all JSON classes derive from JSONObject, this should work.