Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
How convert a String response to an iterable object

I am trying to call a rest end point using Volley (HTTP library) in Android/Java app. Here is my code,

 RequestQueue queue = Volley.newRequestQueue(this);
        String url ="https://covid19datasl.herokuapp.com/countries";


        StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        System.out.println(response);

                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("Error");
            }
        });

But it gives me an String a response like this,

[{"country":"USA","countryCode":"US"},{"country":"India","countryCode":"IN"},{"country":"Brazil","countryCode":"BR"}]

How do I convert this String to an itaratable object?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

No need for any other libraries beside Volley.

Use Volleys JsonArrayRequest for retrieving JSONArray responses.

RequestQueue queue = Volley.newRequestQueue(this);

String url = "http://my-json-feed";

JsonArrayRequest jsonArrayRequest = new JsonArrayRequest
        (Request.Method.GET, url, null, new Response.Listener<JSONArray>() {
    @Override
    public void onResponse(JSONArray response) {
        // do something with the response
    }
}, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
        // TODO: Handle error
    }
});

// Add request to queue 
queue.add(jsonArrayRequest);
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!