【发布时间】:2016-03-16 16:35:43
【问题描述】:
无法理解如何解析这个 json 数组。
[{"id":"154","ontime":"2016-03-15","offtime":"2016-04-14","usluga_id":"2","name":" 50mpbs","period":"30","cost":"300"},
{"id":"152","ontime":"2016-03-15","offtime":"2016-04-14","usluga_id":"4","name":"TV60 ","期间":"30","成本":"100"},
{"id":"156","ontime":"2016-03-15","offtime":"2016-04-04","usluga_id":"5","name":"TV120 ","期间":"20","成本":"200"},
{"id":"153","ontime":"2016-03-15","offtime":"2016-03-30","usluga_id":"6","name":"SMS -check","period":"15","cost":"50"}]
@Generated("org.jsonschema2pojo")
public class UserService {
@SerializedName("id")
@Expose
private String id;
@SerializedName("ontime")
@Expose
private String ontime;
@SerializedName("offtime")
@Expose
private String offtime;
@SerializedName("usluga_id")
@Expose
private String uslugaId;
@SerializedName("name")
@Expose
private String name;
@SerializedName("period")
@Expose
private String period;
@SerializedName("cost")
@Expose
private String cost;
/**
*
* @return
* The id
*/
public String getId() {
return id;
}
/**
*
* @param id
* The id
*/
public void setId(String id) {
this.id = id;
}
/**
*
* @return
* The ontime
*/
public String getOntime() {
return ontime;
}
/**
*
* @param ontime
* The ontime
*/
public void setOntime(String ontime) {
this.ontime = ontime;
}
/**
*
* @return
* The offtime
*/
public String getOfftime() {
return offtime;
}
/**
*
* @param offtime
* The offtime
*/
public void setOfftime(String offtime) {
this.offtime = offtime;
}
/**
*
* @return
* The uslugaId
*/
public String getUslugaId() {
return uslugaId;
}
/**
*
* @param uslugaId
* The usluga_id
*/
public void setUslugaId(String uslugaId) {
this.uslugaId = uslugaId;
}
/**
*
* @return
* The name
*/
public String getName() {
return name;
}
/**
*
* @param name
* The name
*/
public void setName(String name) {
this.name = name;
}
/**
*
* @return
* The period
*/
public String getPeriod() {
return period;
}
/**
*
* @param period
* The period
*/
public void setPeriod(String period) {
this.period = period;
}
/**
*
* @return
* The cost
*/
public String getCost() {
return cost;
}
/**
*
* @param cost
* The cost
*/
public void setCost(String cost) {
this.cost = cost;
}
public class ServicesArray {
private List<UserService> services;
public ServicesArray(){};
public List<UserService> getServices() {
return services;
}
public void setServices(List<UserService> services) {
this.services = services;
}
活动中...
public void GetUserServices(){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://cybergenesis.ru/egor/")
.addConverterFactory(GsonConverterFactory.create())
.build();
APIService service = retrofit.create(APIService.class);
Call<ServicesArray> call = service.getUserServices("egoraa");
call.enqueue(new Callback<ServicesArray>() {
@Override
public void onResponse(Call<ServicesArray> call, retrofit2.Response<ServicesArray> response) {
String[] services = new String[response.body().getServices().size()];
response.body().getServices().toArray(services);
Log.d(TAG,"OKKKK");
}
@Override
public void onFailure(Call<ServicesArray> call, Throwable t) {
Log.d(TAG,"ERROR PROFIT");
}
});
}
日志:D/MainScreen:错误利润
响应为空,我的问题是什么?
【问题讨论】: