我正在制作一个将 SQL 语句发送到 PHP 的应用程序,该 PHP 搜索数据库并返回托管的 JSON。
目前在我的应用程序中,我通过了这个声明,SentenciaFinal 也有这个值:
SELECT Nombre FROM Tierra WHERE Nivel <=1 AND CDE <=1000 AND VDE <=1000 AND Coste <=1000 AND Ataque <=1000 AND Defensa<=1000
错误如下:
10-25 16:12:36.201: E/ServicioRest(1240): Error!
10-25 16:12:36.201: E/ServicioRest(1240): java.lang.IllegalArgumentException: Illegal character in query at index 80: http://proyectosccv.zz.mu/AppAndroid/phps/ConsultaHabilidad.php?sentencia=SELECT Nombre FROM Tierra WHERE Nivel <=1 AND CDE <=1000 AND VDE <=1000 AND Coste <=1000 AND Ataque <=1000 AND Defensa<=1000
10-25 16:12:36.201: E/ServicioRest(1240): at java.net.URI.create(URI.java:727)
10-25 16:12:36.201: E/ServicioRest(1240): at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:75)
10-25 16:12:36.201: E/ServicioRest(1240): at browser.habilidades.Busqueda.colocarList(Busqueda.java:63)
10-25 16:12:36.201: E/ServicioRest(1240): at browser.habilidades.Busqueda.onCreate(Busqueda.java:40)
10-25 16:12:36.201: E/ServicioRest(1240): at android.app.Activity.performCreate(Activity.java:5104)
10-25 16:12:36.201: E/ServicioRest(1240): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
10-25 16:12:36.201: E/ServicioRest(1240): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
10-25 16:12:36.201: E/ServicioRest(1240): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
10-25 16:12:36.201: E/ServicioRest(1240): at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-25 16:12:36.201: E/ServicioRest(1240): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
10-25 16:12:36.201: E/ServicioRest(1240): at android.os.Handler.dispatchMessage(Handler.java:99)
10-25 16:12:36.201: E/ServicioRest(1240): at android.os.Looper.loop(Looper.java:137)
10-25 16:12:36.201: E/ServicioRest(1240): at android.app.ActivityThread.main(ActivityThread.java:5041)
10-25 16:12:36.201: E/ServicioRest(1240): at java.lang.reflect.Method.invokeNative(Native Method)
10-25 16:12:36.201: E/ServicioRest(1240): at java.lang.reflect.Method.invoke(Method.java:511)
10-25 16:12:36.201: E/ServicioRest(1240): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
10-25 16:12:36.201: E/ServicioRest(1240): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
10-25 16:12:36.201: E/ServicioRest(1240): at dalvik.system.NativeStart.main(Native Method)
我运行的代码是这样的:
private void colocarList(String SentenciaFinal) {
try {
HttpGet peticion = new HttpGet(
"http://proyectosccv.zz.mu/AppAndroid/phps/ConsultaHabilidad.php?sentencia="+SentenciaFinal);
peticion.setHeader("content-type", "application/json");
HttpClient httpClient = new DefaultHttpClient();
HttpResponse resp = httpClient.execute(peticion);
String respStr = EntityUtils.toString(resp.getEntity());
JSONArray resparray = new JSONArray(respStr);
int n = resparray.length();
NombreHabilidades = new String[n];
for (int i = 0; i < resparray.length(); i++) {
JSONObject respJSON = resparray.getJSONObject(i);
String nombre = respJSON.getString("Nombre");
NombreHabilidades[i] = nombre;
}
// Rellenamos la lista con los resultados
ArrayAdapter<String> adaptador = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, NombreHabilidades);
list.setAdapter(adaptador);
} catch (Exception ex) {
Log.e("ServicioRest", "Error!", ex);
}
}
我知道如何使用 json 和我的应用程序,我已经获得了互联网连接许可。
我认为发生某事的判断是错误的,但不确定。
非常感谢!= D