解析成功,但是问题是,它仅使用logininClients,ActiveClient没有进行改造,如何在没有对象名称的情况下解析array下的数组?
{
"status": 200,
"success": true,
"messages": "",
"result": [
[
{
"LoggedinClients": 1
}
],
[
{
"ActiveClients": 0
}
]
]
}
部分相关代码:
public class OnlineInfoResponse {
@SerializedName("result")
@Expose
private List<List<OnlineInfoLoggedInResult>> lstLists = null;
public List<List<OnlineInfoLoggedInResult>> getLstLoggedIn() {
return lstLists;
}
public void setLstLists(List<List<OnlineInfoLoggedInResult>> lstLists) {
this.lstLists = lstLists;
}
OnlineInfoLoggedInResult.java
public class OnlineInfoLoggedInResult {
@SerializedName("LoggedinClients")
@Expose
private int loggedinClients;
public int getLoggedinClients() {
return loggedinClients;
}
public void setLoggedinClients(int loggedinClients) {
this.loggedinClients = loggedinClients;
}
@SerializedName("ActiveClients")
@Expose
private int activeClients;
public int getActiveClients() {
return activeClients;
}
public void setActiveClients(int activeClients) {
this.activeClients = activeClients;
}
}
这是我从jsonschema解析的。我在嵌套jsonarray中遇到问题。
答案 0 :(得分:0)
您应该生成以下POJO
public class YourPojoName {
private float status;
private boolean success;
private String messages;
List <List< Object> > result = new ArrayList < ArrayList<Object> > ();
// Getter Methods
public float getStatus() {
return status;
}
public boolean getSuccess() {
return success;
}
public String getMessages() {
return messages;
}
// Setter Methods
public void setStatus(float status) {
this.status = status;
}
public void setSuccess(boolean success) {
this.success = success;
}
public void setMessages(String messages) {
this.messages = messages;
}
}
答案 1 :(得分:0)
public class abbb {
@Expose
@SerializedName("result")
private List<List<Result>> result;
@Expose
@SerializedName("messages")
private String messages;
@Expose
@SerializedName("success")
private boolean success;
@Expose
@SerializedName("status")
private int status;
public List<List<Result>> getResult() {
return result;
}
public void setResult(List<List<Result>> result) {
this.result = result;
}
public String getMessages() {
return messages;
}
public void setMessages(String messages) {
this.messages = messages;
}
public boolean getSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public static class Result {
@Expose
@SerializedName("LoggedinClients")
private int LoggedinClients;
@Expose
@SerializedName("ActiveClients")
private int active_clients;
//genetrate getter setter
}
}