Skip to content Skip to sidebar Skip to footer

Json From .net Wcf To Javascript Array Of Arrays

I'm using jqPlot and I need to turn this JSON which I receive from a WCF service: [{ 'x': 2, 'y': 3 }, { 'x': 25, 'y': 34 }] into this array or arrays: [[2,3],[25,34]] I've tried

Solution 1:

You can use $.map() to do that:

var data = [{ "x": 2, "y": 3 }, { "x": 25, "y": 34 }]

var flattenedResult = $.map(data, function(point) {
  return[[ point.x, point.y ]];
});

Solution 2:

Parse the string into an array of objects:

var json = '[{ "x": 2, "y": 3 }, { "x": 25, "y": 34 }]';
var o = $.parseJSON(json);

Then replace each object in the array with an array:

for (var i=0; i<o.length; i++) o[i] = [o[i].x, o[i].y];  

Post a Comment for "Json From .net Wcf To Javascript Array Of Arrays"