How to fetch JSON array without any key in Retrofit (Android)? How to fetch JSON array without any key in Retrofit (Android)? json json

How to fetch JSON array without any key in Retrofit (Android)?


You Can define a Class representing the JSON Object

import com.google.gson.annotations.Expose;import com.google.gson.annotations.SerializedName;public class Meeting{@SerializedName("Type")@Exposeprivate String type;@SerializedName("Name")@Exposeprivate String name;@SerializedName("StartDate")@Exposeprivate String startDate;@SerializedName("EndDate")@Exposeprivate String endDate;public String getType() {return type;}public void setType(String type) {this.type = type;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getStartDate() {return startDate;}public void setStartDate(String startDate) {this.startDate = startDate;}public String getEndDate() {return endDate;}public void setEndDate(String endDate) {this.endDate = endDate;}}

after that you define Callback for retrofit like thatCall<List<Meeting>> getMeetings();


if you are using Gson parsing then simple do it like this

 var model = Gson().fromJson(response.body()!!.string(), Array<Meeting>::class.java).toList()


Json Response :

{"contacts":{"918888302649":0,"917207251056":0,"918888804581":0}}

POJO Class :

public class ContactSyncResponseModel {    @SerializedName("contacts")    @Expose    private Map<String, String> result;    public Map<String, String> getResult() {        return result;    }    public void setResult(Map<String, String> result) {        this.result = result;    } }