I'm working on json and I really need to get this structure:
{
"Identidade":
[
{ "numero": 1704, "numeroFinal": 1804, "id": 28 },
{ "numero": 1806, "numeroFinal": 1905, "id": 28 },
{ "numero": 1705, "numeroFinal": 1706, "id": 29 },
{ "numero": 1707, "numeroFinal": 1807, "id": 30 }
]
}
But until now I can only get this, and I'm still unable to write Identity at the top
[
{ "numero": 1704, "numeroFinal": 1804, "id": 28 },
{ "numero": 1806, "numeroFinal": 1905, "id": 28 },
{ "numero": 1705, "numeroFinal": 1706, "id": 29 },
{ "numero": 1707, "numeroFinal": 1807, "id": 30 }
]
The code that follows is my current implementation.
public void writeJsonStream(String file, List<Identidade> iden) throws IOException {
JsonWriter writer = new JsonWriter(new OutputStreamWriter(m_Context.openFileOutput(file, Context.MODE_PRIVATE)));
writer.setIndent(" ");
writeArray(writer, util);
writer.close();
}
public void writeArray(JsonWriter writer, List<Identidade> iden) throws IOException {
writer.beginArray();
for (Identidade i : iden) {
writeIdentidade(writer, i);
}
writer.endArray();
}
public void writeIdentidade(JsonWriter writer, Identidade iden) throws IOException
writer.beginObject();
writer.name("numero").value(iden.getM_numero());
writer.name("numeroFinal").value(iden.numeroFinal());
writer.name("id").value(iden.getID());
writer.endObject();
}
Can someone give me a hint on how to add Identity ?