如何从应用程序读取JSON中的Distance Matrix API响应?

时间:2019-01-11 14:36:33

标签: android json httprequest google-distancematrix-api

     String url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins="+expedTextView.getText().toString()+"&destinations="+destTextView.getText().toString()+"&sensor=false&mode=driving&key=AIzaSyC9BT3f2jmmPSJh2ewGfGiuVz1zeIfPX4A";

            HttpClient httpClient = new DefaultHttpClient();

            HttpContext localContext = new BasicHttpContext();

            HttpGet httpGet = new HttpGet(url);

            HttpResponse response = null;
            try {
                response = httpClient.execute(httpGet, localContext);
            } catch (IOException e) {
                e.printStackTrace();
            }
            Toast.makeText(SecondScreen.this, ""+response, Toast.LENGTH_LONG).show();
        }

这是我的代码。我尝试过使用此URL发出一个HTTP请求,该URL的构造很好,但是,当我读取响应时,它看起来根本不像JSON。下面是来自响应的代码。请注意,将链接放入浏览器后,该链接可以很好地工作。

          HTTP/1.1 200 OK [Content-Type: application/json; charset=UTF-8, Date: Fri, 11 Jan 2019 14:26:57 GMT, Expires: Sat, 12 Jan 2019 14:26:57 GMT, Cache-Control: public, max-age=86400, Server: mafe, X-XSS-Protection: 1; mode=block, X-Frame-Options: SAMEORIGIN, Server-Timing: gfet4t7; dur=91, Alt-Svc: quic=":443"; ma=2592000; v="44,43,39,35", Accept-Ranges: none, Vary: Accept-Language,Accept-Encoding, Transfer-Encoding: chunked] cz.msebera.android.httpclient.conn.BasicManagedEntity@2bffe96
          D/HwRTBlurUtils: check blur style for HwToast-Toast, themeResId : 0x7f0d0005, context : com.example.rarestaciu.bikemessengerapp.SecondScreen@309bb49, Nhwext : 6, get Blur : disable with , android.graphics.drawable.NinePatchDrawable@aadbe04

0 个答案:

没有答案