なぜ私の JSON 配列は最後の json 要素なのですか?
これは私のコードです:
@GET
@Path("inregistrareHarta")
@Produces(MediaType.APPLICATION_JSON)
public void getListPuncte(@QueryParam("idTransporturi") int idTransporturi)
{
PuncteDAO puncteInformation = new PuncteDAO();
ArrayList<Puncte> puncteList = puncteInformation.getPuncte(idTransporturi);
Gson gson = new Gson();
JsonArray arrayObj=new JsonArray();
for(int i=0;i<puncteList.size();i++)
{
Puncte puncte = puncteList.get(i);
JsonElement puncteObj = gson.toJsonTree(puncte);
arrayObj.add(puncteObj);
}
JsonObject myObj = new JsonObject();
myObj.add("puncteList", arrayObj);
System.out.println(myObj.toString());
}
これは私が得ている結果です:
{"puncteList":
[
{"idPuncte":7,"idTransport":2,"latitudine":190.0,"longitudine":150.0,"descriere":"2_4"},
{"idPuncte":7,"idTransport":2,"latitudine":190.0,"longitudine":150.0,"descriere":"2_4"},
{"idPuncte":7,"idTransport":2,"latitudine":190.0,"longitudine":150.0,"descriere":"2_4"},
{"idPuncte":7,"idTransport":2,"latitudine":190.0,"longitudine":150.0,"descriere":"2_4"}
]
}
そして、これは私が期待している結果です:
{"puncteList":
[
{"idPuncte":4,"idTransport":2,"latitudine":19.0,"longitudine":0.0,"descriere": "2_1"},
{"idPuncte":5,"idTransport":2,"latitudine":10.0,"longitudine": 50.0,"descriere":"2_2"},
{"idPuncte":6,"idTransport":2,"latitudine":1.0,"longitudine":1.0,"descriere":"2_3"},
{"idPuncte":7,"idTransport":2,"latitudine":30.0,"longitudine":50.0,"descriere":"2_4"}
]
}