我是Android的新手,我想从Amazon DynamoDB检索此JSON,我使用了Retrofit2从Amazon DynamoDB检索此数据。请指导我获取包含多个ArrayList的Output.JSON文件。
{
"configContent": {
"addressTypes": [
"Home",
"Work"
],
"firstTimeInterval": 1,
"gender": [
"Male",
"Female",
"Trans-Female",
"Bi-Gender",
"Non-Binary",
"Gender nonconfirming",
"Undisclosed",
"Rather not say"
],
"languages": [
"English",
"Spanish",
"Marathi",
"Hindi",
"Bengali",
"French",
"Arabic",
"German",
"Italian",
"Dutch",
"Japanese",
"Russia",
"Korean"
],
"mapResetTimeInterval": 30,
"meetingTrackableTime": 3600,
"meetmeSearchContactTimeInterval": 2,
"numberOfParticipants": 8,
"profileToastDelatimebysix": 6,
"profileToastDelayTime": 4,
"secondTimeInterval": 2,
"signupToastdelatimebysix": 6,
"signupToastDelayMedium": 5,
"signupToastDelayTime": 4,
"syncToastMaxTimeInterval": 300,
"syncToastThirdTimeInterval": 180,
"toastDelayTimeForPulse": 3,
"trackingOptions": [
{
"isDeleted": 0,
"isTimeRequired": 1,
"optionName": "Before the meet",
"trackingTime": [
5,
10,
15
]
},
{
"isDeleted": 0,
"isTimeRequired": 1,
"optionName": "After the meet",
"trackingTime": [
5,
10,
15
]
},
{
"isDeleted": 0,
"isTimeRequired": 0,
"optionName": "At the start",
"trackingTime": []
},
{
"isDeleted": 0,
"isTimeRequired": 0,
"optionName": "Never",
"trackingTime": []
}
],
"transportModes": [
"Walking",
"Driving"
]
},
"createdDate": "2018-04-17T10:53:50.721Z",
"id": "bb52dc0f-29d0-4079-99c7-a07c8045a829",
"moduleName": "MeetMe"
}
这是界面
public interface Api {
String BASE_URL = "https://sz3i35gurk.execute-api.eu-west-2.amazonaws.com/dev/";
@GET("meetmeconfigurations")
Call<Hero> getHeroes();
POJO CLASS
Hero.class
public class Hero {
private String id;
private ConfigContent configContent;
private String moduleName;
private String createdDate;
}
ConfigContent.class
public class ConfigContent {
private String mapResetTimeInterval;
private String signupToastdelatimebysix;
private String toastDelayTimeForPulse;
private String profileToastDelatimebysix;
private TrackingOptions[] trackingOptions;
private String firstTimeInterval;
private String signupToastDelayTime;
private String meetingTrackableTime;
private String[] addressTypes;
private String[] languages;
private String signupToastDelayMedium;
private String numberOfParticipants;
private String syncToastMaxTimeInterval;
private String syncToastThirdTimeInterval;
private String profileToastDelayTime;
private String[] gender;
private String meetmeSearchContactTimeInterval;
private String[] transportModes;
private String secondTimeInterval;
}
TrackingOption.class
public class TrackingOptions {
private String optionName;
private String isTimeRequired;
private String isDeleted;
private String[] trackingTime;
}
MainActivity文件
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Api.BASE_URL)
.addConverterFactory(GsonConverterFactory.create()) //Here we are using the GsonConverterFactory to directly convert json data to object
.build();
Api api = retrofit.create(Api.class);
Call<Hero> call = api.getHeroes();
call.enqueue(new Callback<Hero>() {
@Override
public void onResponse(Call<Hero> call, Response<Hero> response) {
Hero heroList = response.body();
data = new ArrayList<>(Arrays.asList(heroList));
Log.d("Data","Data recevied:"+data);
}
@Override
public void onFailure(Call<Hero> call, Throwable t) {
Log.d("error message","error message"+t);
Toast.makeText(getApplicationContext(), t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
因此,当我运行程序时,我得到空值,请帮助解决问题
答案 0 :(得分:0)
使用get set方法重写所有POJO类。例如,我为您完成了ConfigContent
类。
public class ConfigContent {
@SerializedName("addressTypes")
@Expose
private List<String> addressTypes = null;
@SerializedName("firstTimeInterval")
@Expose
private Integer firstTimeInterval;
@SerializedName("gender")
@Expose
private List<String> gender = null;
@SerializedName("languages")
@Expose
private List<String> languages = null;
@SerializedName("mapResetTimeInterval")
@Expose
private Integer mapResetTimeInterval;
@SerializedName("meetingTrackableTime")
@Expose
private Integer meetingTrackableTime;
@SerializedName("meetmeSearchContactTimeInterval")
@Expose
private Integer meetmeSearchContactTimeInterval;
@SerializedName("numberOfParticipants")
@Expose
private Integer numberOfParticipants;
@SerializedName("profileToastDelatimebysix")
@Expose
private Integer profileToastDelatimebysix;
@SerializedName("profileToastDelayTime")
@Expose
private Integer profileToastDelayTime;
@SerializedName("secondTimeInterval")
@Expose
private Integer secondTimeInterval;
@SerializedName("signupToastdelatimebysix")
@Expose
private Integer signupToastdelatimebysix;
@SerializedName("signupToastDelayMedium")
@Expose
private Integer signupToastDelayMedium;
@SerializedName("signupToastDelayTime")
@Expose
private Integer signupToastDelayTime;
@SerializedName("syncToastMaxTimeInterval")
@Expose
private Integer syncToastMaxTimeInterval;
@SerializedName("syncToastThirdTimeInterval")
@Expose
private Integer syncToastThirdTimeInterval;
@SerializedName("toastDelayTimeForPulse")
@Expose
private Integer toastDelayTimeForPulse;
@SerializedName("trackingOptions")
@Expose
private List<TrackingOption> trackingOptions = null;
@SerializedName("transportModes")
@Expose
private List<String> transportModes = null;
public List<String> getAddressTypes() {
return addressTypes;
}
public void setAddressTypes(List<String> addressTypes) {
this.addressTypes = addressTypes;
}
public Integer getFirstTimeInterval() {
return firstTimeInterval;
}
public void setFirstTimeInterval(Integer firstTimeInterval) {
this.firstTimeInterval = firstTimeInterval;
}
public List<String> getGender() {
return gender;
}
public void setGender(List<String> gender) {
this.gender = gender;
}
public List<String> getLanguages() {
return languages;
}
public void setLanguages(List<String> languages) {
this.languages = languages;
}
public Integer getMapResetTimeInterval() {
return mapResetTimeInterval;
}
public void setMapResetTimeInterval(Integer mapResetTimeInterval) {
this.mapResetTimeInterval = mapResetTimeInterval;
}
public Integer getMeetingTrackableTime() {
return meetingTrackableTime;
}
public void setMeetingTrackableTime(Integer meetingTrackableTime) {
this.meetingTrackableTime = meetingTrackableTime;
}
public Integer getMeetmeSearchContactTimeInterval() {
return meetmeSearchContactTimeInterval;
}
public void setMeetmeSearchContactTimeInterval(Integer meetmeSearchContactTimeInterval) {
this.meetmeSearchContactTimeInterval = meetmeSearchContactTimeInterval;
}
public Integer getNumberOfParticipants() {
return numberOfParticipants;
}
public void setNumberOfParticipants(Integer numberOfParticipants) {
this.numberOfParticipants = numberOfParticipants;
}
public Integer getProfileToastDelatimebysix() {
return profileToastDelatimebysix;
}
public void setProfileToastDelatimebysix(Integer profileToastDelatimebysix) {
this.profileToastDelatimebysix = profileToastDelatimebysix;
}
public Integer getProfileToastDelayTime() {
return profileToastDelayTime;
}
public void setProfileToastDelayTime(Integer profileToastDelayTime) {
this.profileToastDelayTime = profileToastDelayTime;
}
public Integer getSecondTimeInterval() {
return secondTimeInterval;
}
public void setSecondTimeInterval(Integer secondTimeInterval) {
this.secondTimeInterval = secondTimeInterval;
}
public Integer getSignupToastdelatimebysix() {
return signupToastdelatimebysix;
}
public void setSignupToastdelatimebysix(Integer signupToastdelatimebysix) {
this.signupToastdelatimebysix = signupToastdelatimebysix;
}
public Integer getSignupToastDelayMedium() {
return signupToastDelayMedium;
}
public void setSignupToastDelayMedium(Integer signupToastDelayMedium) {
this.signupToastDelayMedium = signupToastDelayMedium;
}
public Integer getSignupToastDelayTime() {
return signupToastDelayTime;
}
public void setSignupToastDelayTime(Integer signupToastDelayTime) {
this.signupToastDelayTime = signupToastDelayTime;
}
public Integer getSyncToastMaxTimeInterval() {
return syncToastMaxTimeInterval;
}
public void setSyncToastMaxTimeInterval(Integer syncToastMaxTimeInterval) {
this.syncToastMaxTimeInterval = syncToastMaxTimeInterval;
}
public Integer getSyncToastThirdTimeInterval() {
return syncToastThirdTimeInterval;
}
public void setSyncToastThirdTimeInterval(Integer syncToastThirdTimeInterval) {
this.syncToastThirdTimeInterval = syncToastThirdTimeInterval;
}
public Integer getToastDelayTimeForPulse() {
return toastDelayTimeForPulse;
}
public void setToastDelayTimeForPulse(Integer toastDelayTimeForPulse) {
this.toastDelayTimeForPulse = toastDelayTimeForPulse;
}
public List<TrackingOption> getTrackingOptions() {
return trackingOptions;
}
public void setTrackingOptions(List<TrackingOption> trackingOptions) {
this.trackingOptions = trackingOptions;
}
public List<String> getTransportModes() {
return transportModes;
}
public void setTransportModes(List<String> transportModes) {
this.transportModes = transportModes;
}
}