Using Gson, I am serializing a list of objects in the following manner:
String responseMessage = new Gson().toJson(pages.get(pagenumber));
Now, I want to include an additional property that can be accessed in JavaScript, which is not related to the list:
{"numberofpages":x}
My attempted solution was:
JsonElement responsemessage = new Gson().toJsonTree(pages.get(pagenumber));
JsonObject message = (JsonObject) responsemessage;
message.addProperty("numberofpages",numberofpages);
However, I encountered an issue because responsemessage
was recognized as a JSONArray. How can I encode more data within the String version of responseMessage
to be utilized in JavaScript?:
$.get("/lod1/Data",{pagenumber: page},function(list){
console.log(list);
//???
//if(list.numberofpages == 5){
// }
$.each(list,function(index,card){
$("#questionsforsets").append('<tr><td class="questioncell"><div class="longtexttd">'+card.card+'</div></td><td>'+card.category+'</td><td>'+card.made+'</td><td>'+card.missed+'</td></tr>');
});
},"json");