Search code examples
androidlistviewandroid-recyclerviewretrofit2json-api

Parse JSON String Using Retrofit, & Populate to List view/Recycler view?


I am new to Retrofit and Android, and now i am stuck at receiving the JSON from API.

I want full solution to parse this JSON and populate it into RecyclerView or ListView.

The Sample of JSON Data is below:

["C","Python","Swift","Ruby","Javascript","PHP","C#","Java"]

Solution

  • Add this to your Retrofit interface:

    @GET("api/programming_languages")
    Call<List<String>> getLanguagesList();
    

    And use it like this:

    Call<List<String>> languagesCall = service.getLanguagesList();
    languagesCall.enqueue(new Callback<List<String>>() {
        @Override
        public void onResponse(Response<List<String>> response) {
            List<String> languages = response.body();
        }
    
        @Override
        public void onFailure(Throwable t) {
    
        }
    });
    

    There are many other tutorials for Retrofit 2.0 so go and find something.