【发布时间】:2023-04-10 23:50:01
【问题描述】:
我使用以下代码从 php 页面 (www.ace.ucv.ro/android/android.php) 中检索基本上 JSON 格式的字符串。
出于某种原因,无论我尝试什么,字符串“result”仍然为空,其中没有存储任何内容,即使我使用特殊函数将其从 InputStream 转换为 String(使用 BufferedReader)。
我要存储的字符串称为“RESULT”。
public void connect(String url){
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse response;
try{
response = client.execute(httpGet);
Log.i("Praeda", response.getStatusLine().toString());
HttpEntity entity = response.getEntity();
if(entity != null){
result = entity.getContent().toString();
}
if(entity == null){
result = "failed";
}
}catch(Exception e){
e.printStackTrace();
}
}
您可能有任何建议都会很棒...
【问题讨论】:
-
您是否验证了服务器确实在发送您认为它正在发送的 JSON?
-
它生成的页面只是带有一个有效 JSON 字符串的 HTML。 (经过测试,因此它是有效的 JSON)。问题是它没有从页面中获取任何内容:www.ace.ucv.ro/android/android
-
会不会是数据太长了?