我正在使用HTTP加密。如果加密为false,则webservice发送一个简单的JSON,其值为false,如果加密正确,则向数据发送JSON数组。JSON解码的问题... JSONException:在chatacter的输入结束0
test()是使用一组login:password“尝试”api的方法。
我使用,我收到JSON麻烦(JSONException:人品0输入完)
这里的entiere代码(我不认为这整个代码将投放,但...),只是代码后,使一个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 .JSONEx ception:在字符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 =
感谢帮助我:d
谢谢:D,但有一个例外。 “ret”什么都不显示,它会说没有收到JSON?谢谢 – clement 2011-12-30 15:01:49
它看起来像你已经确定ret是null或空你编辑的问题。现在你应该弄清楚为什么你的web服务调用什么都不返回。你看过web服务对象吗?它是否返回404或其他东西?另外,你是否确定你正在清单中请求Internet权限? – Jack 2011-12-30 15:06:03
是的,互联网连接正在运行,显然没有返回任何东西...所以我会改变webservice ...谢谢 – clement 2011-12-30 17:42:40