I get a JSON array of objects from a servlet and try to populate a control with a table in a java script.
Here is my code, for some reason it puts double quotes at the beginning and at the end, which is not accepted by the table control to populate the values. how can i remove these double quotes at the beginning and at the end.
aData = [{"A":"one","B":"Two","C":"Three","D":"8","E":"No","F":"Business","G":"0", "L1H":"Analytics"},{"A":"ones","B":"Twos","C":"Threes","D":"85","E":"Nos", "F":"BusinessD","G":"0","L1H":"AnalyticsM"}] var oModel = new sap.ui.model.json.JSONModel(); oModel.setData({modelData: aData}); var oTable=sap.ui.getCore().byId("id1"); oTable.setModel(oModel); oTable.bindRows("/modelData"); // This static code of aData is working fine in // my Table control of HTMl page. //Here, i Wanted to get values dynamically from servlet and populate it in Table. var global; $.get('someServlet', function(data) { var abc, xyz; for(var i=0;i<(data.length);i++){ abc='{'+'\"A\":'+'\"'+data[i].A+'\"'+','+'\"B":'+'\"'+data[i].B+'\"'+', '+'\"C\":'+'\"'+data[i].C+'\"'+','+'\"D\":'+'\"'+data[i].D+'\"'+', '+'\"E\":'+'\"'+data[i].E+'\"'+','+'\"F\":'+'\"'+data[i].F+'\"'+', '+'\"G\":'+'\"'+data[i].G+'\"'+','+'\"H\":'+'\"'+data[i].H+'\"}'; if (xyz===undefined) xyz=abc; else xyz=abc+','+xyz; global = xyz; } global="["+global+"]"; var oModel = new sap.ui.model.json.JSONModel(); oModel.setData({modelData: global}); var oTable=sap.ui.getCore().byId("id1"); oTable.setModel(oModel); oTable.bindRows("/modelData"); }); //global="[{"A":"one","B":"Two","C":"Three"}...]" //alert(global); Displaying without double quotes as expected. //when I see the value in Chrome debugger double quotes are appearing at begin&End
So, I have a value in a global variable, with double quotes.
//global="[{"A":"one","B":"Two","C":"Three","D":"8","E":"No","F":"Business","G":"0","L1H":"Analytics"},
{"A": "units", "B": "deuces", "C": "triples", "D": "85", "E": "nose", "F": "BusinessD" "G ":" 0 "," L1H ":" AnalyticsM "}]"
How can I get rid of these double quotes at the beginning and end of this result? Define JSONArray objects? If I put Alert, it is displayed without double quotes. when I see this global variable in the Chrome debugger, it appears with double quotes and does not populate the values โโin the table control. It is a little difficult for me with my code to populate the values โโin the Table control that come from the Servlet in JSON / String / Array format. Please, help.
Appreciate any input and help.