问题描述
正在尝试使用volley
映射此json。但是我每次都在构造函数内部不断出现错误。
[
{
"id": 19,"time_created": {
"date": "2018-09-18 09:24:34.000000","timezone_type": 3,"timezone": "America/Chicago"
},]
所以我需要获取time_created对象。这是我的模特班; 公共类NeighbourhoodOther实施可序列化{
public int id;
public TimeCreated timeCreated;
public NeighbourhoodOther(){
}
public NeighbourhoodOther(int id,TimeCreated timeCreated ) {
this.id = id;
this.timeCreated= time_created;
}
public TimeCreated getTimeCreated() {
return timeCreated;
}
public void setTimeCreated(TimeCreated timeCreated) {
this.timeCreated = timeCreated;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public static class TimeCreated {
public String timezone;
public int timezoneType;
public String date;
public String getTimezone() {
return timezone;
}
public void setTimezone(String timezone) {
this.timezone = timezone;
}
public int getTimezoneType() {
return timezoneType;
}
public void setTimezoneType(int timezoneType) {
this.timezoneType = timezoneType;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
}
}
这是我试图用凌空抽空的方法,但每次都会出现错误。
for (int i = 0; i < neighOther.length(); i++) {
JSONObject neighOtherObject = neighOther.getJSONObject(i);
int id = neighOtherObject.getInt("id");
NeighbourhoodOther.TimeCreated timeCreated = neighOtherObject.getJSONObject("time_created");
NeighbourhoodOther neighbourhoodOther = new NeighbourhoodOther(id,time_created);
otherNeighbourHoodList.add(neighbourhoodOther);
}
构造函数中的错误表明它期望使用JSONObject而不是TimeCreated
。什么是获取数据的最佳方法。我需要将date
字符串传递给TextView
。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)