How to use curl url for json api integration in android How to use curl url for json api integration in android curl curl

How to use curl url for json api integration in android


Use Volley to do the cURL request.

private void getResponse(){    String URL = "https://api.infermedica.com/v2/symptoms";    RequestQueue queue = Volley.newRequestQueue(this);    StringRequest request = new StringRequest(Request.Method.GET, URL,            new Response.Listener<String>() {                @Override                public void onResponse(String response) {                    Log.e("Check Response",response);                }            },            new Response.ErrorListener() {                @Override                public void onErrorResponse(VolleyError error) {                    Log.e("Check Error","Error");                }            }    ){        @Override        public byte[] getBody() throws AuthFailureError {            return new byte[]{};        }        @Override        public Map<String, String> getHeaders() throws AuthFailureError {            Map<String,String> map = new HashMap<>();            map.put("Content-Type","application/json");            map.put("Accept", "application/json");            map.put("app_id","90f10c6a");            map.put("app_key","9d23d9250d9f2ee8aa49efda732e4d3d");            return map;        }    };    request.setRetryPolicy(new DefaultRetryPolicy(15000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_MAX_RETRIES));    queue.add(request);}


This is my function to get JSON object

public JSONObject getJSONFromUrl(String url) {    // Making HTTP request    try {        // defaultHttpClient        DefaultHttpClient httpClient = new DefaultHttpClient();        HttpPost httpPost = new HttpPost(url);        HttpResponse httpResponse = httpClient.execute(httpPost);        HttpEntity httpEntity = httpResponse.getEntity();        is = httpEntity.getContent();    } catch (UnsupportedEncodingException e) {        e.printStackTrace();    } catch (ClientProtocolException e) {        e.printStackTrace();    } catch (IOException e) {        e.printStackTrace();    }    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();        json = sb.toString();    } catch (Exception e) {        Log.e("Buffer Error", "Error converting result " + e.toString());    }    // try parse the string to a JSON object    try {        jObj = new JSONObject(json);    } catch (JSONException e) {        Log.e("JSON Parser", "Error parsing data " + e.toString());    }    // return JSON String    return jObj;}

How can i add your code in it?