Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Google places和自动完成Edittext_Android_Httpclient_Google Places - Fatal编程技术网

Android Google places和自动完成Edittext

Android Google places和自动完成Edittext,android,httpclient,google-places,Android,Httpclient,Google Places,为什么下面的代码只返回一个“{”即JSON字符串的开头,而不是整个JSON?当我在浏览器中键入URL时,它会返回完整的JSON。 我试图缓冲回应,但似乎没有任何效果?有人能解释为什么吗 HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet("https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Nasik%20&a

为什么下面的代码只返回一个“{”即JSON字符串的开头,而不是整个JSON?当我在浏览器中键入URL时,它会返回完整的JSON。 我试图缓冲回应,但似乎没有任何效果?有人能解释为什么吗

HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Nasik%20&types=geocode&language=en&sensor=true&key=API-KEY");
HttpResponse response = httpclient.execute(httpget);
InputStream is = response.getEntity().getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
Toast.makeText(this, br.readLine(), Toast.LENGTH_LONG).show();      

你只是在读你回答的第一行


试着这样做:

你只是在读你回答的第一行

试试这样的方法:

这样试试

try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        Log.d("Json Output",sb.toString());
    } catch (Exception e) {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }
更新:

您需要阅读每一行,当前您正在尝试阅读第一行。

请尝试这种方式

try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        Log.d("Json Output",sb.toString());
    } catch (Exception e) {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }
更新:


您需要读取每一行,当前您正在尝试读取第一行。

您正在使用函数br.readline()。正如函数名所示,它只读取一行。要完全解析它,请使用

StringBuilder sb = new StringBuilder();
 String line = null;
 while ((line = br.readLine()) != null) {
    sb.append(line + "\n");
}
Toast.makeText(this, sb.toString(), Toast.LENGTH_LONG).show();

您正在使用函数br.readline()。正如函数名所示,它只读取一行。要完全解析它,请使用

StringBuilder sb = new StringBuilder();
 String line = null;
 while ((line = br.readLine()) != null) {
    sb.append(line + "\n");
}
Toast.makeText(this, sb.toString(), Toast.LENGTH_LONG).show();