Transposing Json Data
I know there are threads on this, but I dont get it and might need help on my json file. I want to bind a json to one of my SAPUI5 controls, but I dont get it converted. The thing
Solution 1:
Please find the code below:
var data = {d :
[
{
Mon01: "03/2015",
Mon02: "04/2015",
Mon03: "05/2015",
},
{
Mon01: "1,0",
Mon02: "3,0",
Mon03: "5,0",
},
{
Mon01: "2,0",
Mon02: "4,0",
Mon03: "6,0",
Mon04: "",
Mon05: "",
Mon06: "",
},
{
Mon01: "10,0",
Mon02: "11,0",
Mon03: "12,0",
Mon04: "",
Mon05: "",
Mon06: "",
}
],
length: 3};
//console.log(data.d[0]);
var keys = [];
for(var key in data.d[data.length]){
//console.log(key);
keys.push(key);
}
var newObj = {d:[]};
newObj['length'] = data.length;
for(var k =0;k<data.length;k++){
var obj = {};
for(var cnt in keys){
obj[keys[cnt]] = "";
}
newObj.d.push(obj);
}
for(var k =0;k<data.length;k++){
//var obj = {};
//console.log(k);
for(var j=0;j<data.length;j++){
newObj.d[k][keys[j]] = data.d[j][keys[k]];
}
}
console.log(newObj);
Post a Comment for "Transposing Json Data"