I have a situation where I am creating an object and pushing it into an array. After that, I convert it into JSON format. When I display the dataCharts using an alert, it is returned in this form:
[{"AllLinks":"Link9","LinkURL":"url1"},{"AllLinks":"Link6","LinkURL":"url2"}]
But actually, I want it to be like this:
[{AllLinks:"Link9",LinkURL:"url1"},{AllLinks:"Link6",LinkURL:"url2"}]
The code I am using is as follows:
$.ajax({
url: url,
type: "get",
headers: {"Accept": "application/json;odata=verbose"},
success: function (data) {
var array = [];
for (var i=0; i < data.d.results.length; i++) {
var item = data.d.results[i];
array.push({
AllLinks: item.AllLinks,
LinkURL: item.LinkURL.Url
});
}
dataCharts = JSON.stringify(array);
alert(dataCharts);
AddDefaultLinks(dataCharts);
},
error: function (data) {
alert(data.responseJSON.error);
}
});