0

In my android application I want to search google for a particular query and get the response in json format using volley or retrofit. How can I implement that?

I tried this link

I added volley as a library and wrote below code

RequestQueue queue = Volley.newRequestQueue(this);
String url = "http://www.google.com";

JsonArrayRequest req = new JsonArrayRequest(url, 
    new Response.Listener<JSONArray> () {
        @Override
        public void onResponse(JSONArray response) {
            try {
                VolleyLog.v("Response:%n %s", response.toString(4));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, 
    new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            VolleyLog.e("Error: ", error.getMessage());
        }
    });

    queue.add(req);
Community
  • 1
  • 1
Jyothish
  • 587
  • 2
  • 8
  • 24

1 Answers1

0

By making calls to www.google.com you will always have an HTML response, in order to get response with other format (Json) you should take a look at Google Custom Search.

Retrofit or Volley are helpers to make HTTP requests but can not change server response format or parse HTML to JSON.

Gaëtan Maisse
  • 12,208
  • 9
  • 44
  • 47