JSON.stringify not generating correct json

I am having problems with JSON.stringify because I cannot create the json format of the model I want to convert. The screen below was the result of JSON.stringify and as you can see in the highlighted part there are some jaggies in the json itself.enter image description here

Below is my code to populate the model:

LookupBase[] lCityLookups = bgReportsUtil.GetLookupCities(_PersonUID, _ClientUID);
JsonResult json = new JsonResult();
json.Data = lCityLookups; //support;
json.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
json.MaxJsonLength = int.MaxValue;
return json;

      

Below is my javascript code:

$.ajax({
    url: "SaladEntry/FillData",
    type: "POST",
    cache: false,
    contentType: "application/json;",
    data: paramSerialized,
    success: function (resultVal) {
    alert(JSON.stringify(resultVal));
});

      

The problem is above, but it doesn't completely solve my real problem. I want to create a chart using google chart and then create an image file and save it to the server, but I am stuck with this error. enter image description here

If you go to the place where the error occurred. enter image description here

This is the code for how I am creating the chart.

        var arrMain = [];
    for (var i = 0; i < resultVal.length; i++) {
    var arr = [resultVal[i].ScaleMin, resultVal[i].PK, resultVal[i].CountryNo, resultVal[i].stringEffectiveDate, resultVal[i].ScaleMax, String(resultVal[i].Currency)];
    arrMain.push(arr);
    }
    console.log(arrMain);   //to remove
    var data = new google.visualization.DataTable();
    data.addColumn('number', 'ScaleMin');
    data.addColumn('string', 'PK');
    data.addColumn('number', 'CountryNo');
    data.addColumn('string', 'stringEffectiveDate');
    data.addColumn('number', 'ScaleMax');
    data.addColumn('string', 'Currency');
    data.addRows(arrMain);

    var options = {
'title': 'Title',
'width': 800,
'height': 600
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
google.visualization.events.addListener(chart, 'ready', function () {
chart_div.innerHTML = '<img src="' + chart.getImageURI() + '">';
});
chart.draw(data, options);
$.ajax({
url: "SaladEntry/SaveToLocal",
type: "POST",
data: { 'jsonData': chart.getImageURI() },
success: function (ret) {
alert(ret);
}
});

      

+3


source to share


2 answers


as stated in the error you are trying to get an image of the chart before the chart is drawn

move the ajax column inside the 'ready'

event chart ...



see next snippet ...

google.visualization.events.addListener(chart, 'ready', function () {
  chart_div.innerHTML = '<img src="' + chart.getImageURI() + '">';

  $.ajax({
    url: "SaladEntry/SaveToLocal",
    type: "POST",
    data: { 'jsonData': chart.getImageURI() },
    success: function (ret) {
      alert(ret);
    }
  });
});

      

0


source


resultVal

already compressed, you can call directly alert(resultVal)

;



+1


source







All Articles