호스트에서 mysql 데이터베이스를 사용하고 있습니다. 호스트에서 데이터를 받기를 원하지만 텍스트 뷰로 데이터를 가져올 때 비어 있습니다.php Json 빈 텍스트보기를 받고
public class MainActivity extends Activity {
TextView tv1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv1=(TextView)findViewById(R.id.name);
Loader loader = new Loader(getApplicationContext());
tv1.setText(loader.loadInBackground());
}
public static class Loader extends AsyncTaskLoader<String>{
public Loader (Context contexto)
{
super(contexto);
}
@Override
public String loadInBackground() {
String resultado = "";
String entrada = "";
DefaultHttpClient cliente = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://comupunt.esy.es/cities.php");
try {
HttpResponse execute = cliente.execute(httpget);
InputStream contenido = execute.getEntity().getContent();
BufferedReader buffer = new BufferedReader(new InputStreamReader(contenido));
String s="";
while((s=buffer.readLine())!=null)
resultado+=s;
{
}
} catch (Exception e) {
// TODO: handle exception
}
try {
JSONObject object = new JSONObject(resultado);
JSONArray jarray = object.getJSONArray("cities");
for (int i=0;i<jarray.length();i++)
{
JSONObject jobject = jarray.getJSONObject(i);
String name=jobject.getString("name");
entrada += name;
}
} catch (Exception e) {
// TODO: handle exception
Log.e("WebService", e.getMessage());
}
return entrada;
}
}
}
JSON과 PHP이
얻을 { "도시": [{ "이름": "토르"}]}
과 로그 캣 :
12-02 04:24:01.492: E/WebService(2190): End of input at character 0 of
감사
가능한 중복 http://stackoverflow.com/questions/24301521/jsonexception-end-of-input-at-character-0 또는 http://stackoverflow.com/questions/ 23170610/error-parsing-data-org-json-jsonexception-of-0-of-character-0- – Chitrang
나는 logcat에 오류가 있습니다. –