請幫助我。我有以下的JSON字符串,至極我應該解析到POJO:需要幫助創建類使用GSON從json字符串映射到pojo的類
{
"Status": "true",
"Result": {
"rows": {
"row": {
"status": true,
"subareas": [
{
"nome": "Associacao Utente",
"id": 9,
"grafs": {
"rows": [
{
"id": 6,
"nome": "AssociacaoUtente",
"tipo": "PIE",
"serv": "MV_AS_UTENTE_POR_NEGOCIO",
"periodo": "ANO"
}
]
}
},
{
"nome": "Chaves",
"id": 60,
"grafs": {
"rows": [
{
"id": 35,
"nome": "ChavesCriadosporano",
"tipo": "LINHA",
"serv": "MV_ASSOC_TOTAL_CHAVES",
"periodo": "ANO"
},
{
"id": 592,
"nome": "ChavesAssociadoAoUserPortal",
"tipo": "BAR",
"serv": "MV_ASSOC_USER_CHAVES",
"periodo": "TODOS"
},
{
"id": 593,
"nome": "ChavesAssociadoAoNegocios",
"tipo": "BAR",
"serv": "MV_ASSOC_CHAVES",
"periodo": "TODOS"
}
]
}
}
]
}
}
}
}
,我有這些類反序列化到POJO,至極的工作,感謝SAURABH:
public class Example {
private String Status;
private Result Result;
public String getStatus() {
return Status;
}
public void setStatus(String status) {
Status = status;
}
public Result getResult() {
return Result;
}
public void setResult(Result result) {
Result = result;
}
@Override
public String toString() {
return "Example [Status=" + Status + ", Result=" + Result + "]";
}
}
public class Result {
private Rows rows;
public Rows getRows() {
return rows;
}
public void setRows(Rows rows) {
this.rows = rows;
}
@Override
public String toString() {
return "Result [rows=" + rows + "]";
}
}
public class Rows {
private Row row;
public Row getRow() {
return row;
}
public void setRow(Row row) {
this.row = row;
}
@Override
public String toString() {
return "Rows [row=" + row + "]";
}
}
import java.util.ArrayList;
import java.util.List;
public class Row {
private Boolean status;
private List<Subarea> subareas = new ArrayList<Subarea>();
public Boolean getStatus() {
return status;
}
public void setStatus(Boolean status) {
this.status = status;
}
public List<Subarea> getSubareas() {
return subareas;
}
public void setSubareas(List<Subarea> subareas) {
this.subareas = subareas;
}
@Override
public String toString() {
return "Row [status=" + status + ", subareas=" + subareas + "]";
}
}
public class Subarea {
private String nome;
private Integer id;
private Grafs grafs;
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Grafs getGrafs() {
return grafs;
}
public void setGrafs(Grafs grafs) {
this.grafs = grafs;
}
@Override
public String toString() {
return "Subarea [nome=" + nome + ", id=" + id + ", grafs=" + grafs
+ "]";
}
}
import java.util.ArrayList;
import java.util.List;
public class Grafs {
private List<Row_> rows = new ArrayList<Row_>();
public List<Row_> getRows() {
return rows;
}
public void setRows(List<Row_> rows) {
this.rows = rows;
}
@Override
public String toString() {
return "Grafs [rows=" + rows + "]";
}
}
public class Row_ {
private Integer id;
private String nome;
private String serv;
private String periodo;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getServ() {
return serv;
}
public void setServ(String serv) {
this.serv = serv;
}
public String getPeriodo() {
return periodo;
}
public void setPeriodo(String periodo) {
this.periodo = periodo;
}
@Override
public String toString() {
return "Row_ [id=" + id + ", nome=" + nome + ", serv=" + serv
+ ", periodo=" + periodo + "]";
}
}
我需要幫助填充從JSON接收的數據到回收者視圖,除以子區域。我很困惑如何創建適配器。請幫幫我。
我看到的都是一些POJO的,但沒有將JSON轉換爲POJO的代碼。 – hotzst
考慮使用JSON和檢查瞭解如何:http://stackoverflow.com/questions/2591098/how-to-parse-json-in-java –