1
I am 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 so far I can only get this one, and I still can’t write the 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 following code 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?
I’m sure this can help you: https://stackoverflow.com/a/18983290/5191209
– Samuel Rizzon