javascript: json data parsing

underground_cs_

New Member
JSON data is pulled like below:Client:\[code\]$.ajax({ type: "POST", url: "Default.aspx/SendJsonUpadtes", data: "{}", contentType: "application/json", dataType: "json", success: function (msg) { $("#Result").text(msg.d); alert(msg.d); } });\[/code\]Asp.net Serverside code:\[code\][WebMethod(EnableSession = false)] public static string SendJsonUpadtes() { return JSONFromCSV(); } public static string JSONFromCSV() { //var reader = new StreamReader(File.OpenRead(@"D:\logs\electricity\data.csv")); var lines = File.ReadAllLines(@"D:\logs\electricity\data.csv"); object[,] data = http://stackoverflow.com/questions/15787137/new object[lines.Count(), 2]; int i = 0; string jsonStr ="["; lines.ToList().ForEach(line => { jsonStr += "["+line+"]"; i++; if (i < lines.Count()) jsonStr += ","; }); jsonStr += "]"; return jsonStr; }\[/code\]I get the data \[quote\] "[[10,20],[20,30],[30,40]]"\[/quote\]Data is being brorought from asp.net page to feed the chart made of highcharts.I couldnt directly feed the chart. so tried to parse it and then feed it.
Now, I need to make a data array that is like below:\[code\]var dataArray = [{data:[]},{data:[]}];\[/code\]Actually something like this\[code\]var dataArray = [{data:[]},{data:[]}]; $.get('data.csv', function(data) { var lines = data.split('\n'); $.each(lines, function(lineNo, line) { var items = line.split(','); dataArray[0].data.push(parseFloat(items[0])); dataArray[1].data.push(parseFloat(items[1])); }); });\[/code\]and\[quote\] series: [{ data: dataArray }]\[/quote\]data in csv used to be like
10,20
20,30
30,40 but the current requirement is different, I am reading the csv file converting it to JSON and sending it to client. which becomes "[[10,20],[20,30],[30,40]]"How can i do it using Javascript or JQuery!Any other better ideas?
 
Back
Top