Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在C#中查看和/或读取JSON对象的内容?_Javascript_C#_Json_Highcharts - Fatal编程技术网

Javascript 如何在C#中查看和/或读取JSON对象的内容?

Javascript 如何在C#中查看和/或读取JSON对象的内容?,javascript,c#,json,highcharts,Javascript,C#,Json,Highcharts,我正在从事一个项目,该项目使用数据生成“Highcharts”图。基本上,它只是一个x/y线系列图,但图表使用了错误的x轴数据。我正试图弄清楚为什么会发生这种情况。我的代码片段如下所示: var data = this.costAnalyzerService.OpenCostWindow(DataToSend, CurrentTrain, CustId); var obj = Json(data, JsonRequestBehavior.AllowGet); return obj; “数据”变

我正在从事一个项目,该项目使用数据生成“Highcharts”图。基本上,它只是一个x/y线系列图,但图表使用了错误的x轴数据。我正试图弄清楚为什么会发生这种情况。我的代码片段如下所示:

var data = this.costAnalyzerService.OpenCostWindow(DataToSend, CurrentTrain, CustId);
var obj = Json(data, JsonRequestBehavior.AllowGet);
return obj;
“数据”变量的类型为
Systems.Collections.Generic.List

基本上,该变量中的所有数据都是正确的。int应该是我的x轴,两个double是我的两组线系列数据。我有理由相信生成绘图的代码没有使用“int”作为x轴。相反,它只是简单地使用1,2,3…,N个点作为x轴编号

我怎样才能窥视这个“JSON”对象,看看发生了什么以及它返回了什么。如果我一步一步地完成代码,图表就会生成,应用程序的执行就会完成。在此点之后,没有更多的步骤点需要调试。从字面上看,函数返回JSON对象并完成。据我所知,它甚至没有返回到调用函数

以下是我正在使用的完整方法:

 public JsonResult PlotCostAnalyzerChart(double acidPrice = 0.0, double causticPrice = 0.0, int acidUsage = 0, int causticUsage = 0, int cationResin = 0, int anionResin = 0, bool loadOnSettingsUpdate = false)
    {
        try
        {
            PriceData DataToSend = this.Session["Data_ToSend"] != null ? Session["Data_ToSend"] as PriceData : new PriceData();
            string CustId = this.Session["CustomerId"] != null ? Session["CustomerId"].ToString() : string.Empty;

            if (loadOnSettingsUpdate)
            {
                DataToSend.AcidPrice = acidPrice;
                DataToSend.CausticPrice = causticPrice;
                DataToSend.AcidUsage = acidUsage;
                DataToSend.CausticUsage = causticUsage;
                DataToSend.AmountCation = cationResin;
                DataToSend.AmountAnion = anionResin;
            }
            else
            {
                DataToSend.AcidUsage = 6;
                DataToSend.CausticUsage = 6;
                DataToSend.AmountCation = 600;
                DataToSend.AmountAnion = 600;
            }

            int CurrentTrain = 1;//set the current train in scope
            //if (Session["SelectedTrain"]!=null)
            //{
            //    CurrentTrain = int.Parse(Session["SelectedTrain"].ToString());
            //}
            var data = this.costAnalyzerService.OpenCostWindow(DataToSend, CurrentTrain, CustId);
            var obj = Json(data, JsonRequestBehavior.AllowGet);
            return obj;
        }
        catch
        {
            throw;
        }
    }
非常感谢您的投入、建议和建议

下面是一些我认为正在生成绘图的java脚本:

$(function () {
$.ajax({
    url: 'PlotCostAnalyzerChart',
    type: "GET",
    dataType: "json",
    success: function (jsonData) {
        $.ajax({
            url: 'GetCumulativeSavings',
            type: 'GET',
            success: function (CumulativeSavingsData) {
                $("#CumulativeSavings").empty();
                $("#CumulativeSavings").html(CumulativeSavingsData);
            },
            error: function (xhr) {
                window.location.href = "/ClientDatabase/Errorview";
            }
        });
        var arrxaxis = new Array();
        var arrWithOutClean = new Array();
        var arrWithClean = new Array();
        for (var i = 0 ; i < jsonData.length ; i++) {
            var mxaxis = new Object();
            var mWithOutClean = new Object();
            var mWithClean = new Object();
            mxaxis = jsonData[i];
            mWithOutClean = jsonData[i];
            mWithClean = jsonData[i];
            arrxaxis.push(mxaxis.Item1);
            arrWithOutClean.push(mWithOutClean.Item2);
            arrWithClean.push(mWithClean.Item3);
        }
        //alert(arr);
        $('#graph_CostAnalyzer').empty();
        $('#graph_CostAnalyzer').highcharts({
            chart: {
                zoomType: 'x'
            },
            title: {
                text: 'Cost Analyzer',
                x: -20 //center
            },
            xAxis: {
                title: {
                    text: 'Number of Weeks'
                }
            },
            yAxis: {
                title: {
                    text: 'Cost of Operations'
                }
            },
            credits: {
                enabled: false
            },
            tooltip: {
                crosshairs: true,
                formatter: function () {
                    return 'Week Number : ' + this.point.x + '<br>' + this.series.name + ' : ' + Highcharts.numberFormat(this.point.y, 2) + '<br>' + 'Click on chart to get cost analysis';
                }

            },
            plotOptions: {
                series: {
                    cursor: 'pointer',
                    point: {
                        events: {
                            click: function (e) {      
                          $("#CostAnalyzerResultsTable").fadeOut(300);
                                $.ajax({
                                    url: 'GetResultsTable',
                                    type: "GET",
                                    data: { weekNumber: this.x },
                                    success: function (CostAnalyzerResultsData) {
                                        //alert(CostAnalyzerResultsData);
                                        $("#CostAnalyzerResultsTable").empty();
                                        $("#CostAnalyzerResultsTable").html(CostAnalyzerResultsData);
                                        //FADEOUT AND FADEIN           
                                        $("#CostAnalyzerResultsTable").fadeIn(400);
                                    }
                                });
                            }
                        }
                    },
                    marker: {
                        lineWidth: 1
                    }
                }
            },
            legend:{
                enabled: true,
                layout: 'horizontal',
                borderWidth: 1
            },                
            series: [{
                name: 'With RTI Cleaning',
                data: arrWithClean
            },
            {
                name: 'Without RTI Cleaning',
                data: arrWithOutClean
            }]
        });
    }
});
$(函数(){
$.ajax({
url:“PlotCostAnalyzerChart”,
键入:“获取”,
数据类型:“json”,
成功:函数(jsonData){
$.ajax({
url:'GetCumulativeSavings',
键入:“GET”,
成功:功能(累积数据){
$(“#累计设置”).empty();
$(“#CumulativeSavings”).html(CumulativeSavingsData);
},
错误:函数(xhr){
window.location.href=“/ClientDatabase/Errorview”;
}
});
var arrxaxis=新数组();
var arrWithOutClean=新数组();
var arrhithclean=新数组();
对于(var i=0;i“+this.series.name+”:“+Highcharts.numberFormat(this.point.y,2)+”
“+”单击图表获取成本分析”; } }, 打印选项:{ 系列:{ 光标:“指针”, 要点:{ 活动:{ 点击:功能(e){ 美元(“#成本分析结果表”)。淡出(300); $.ajax({ url:'GetResultsTable', 键入:“获取”, 数据:{weekNumber:this.x}, 成功:函数(CostAnalyzerResultsData){ //警报(CostAnalyzerResultsData); $(“#CostAnalyzerResultsTable”).empty(); $(“#CostAnalyzerResultsTable”).html(CostAnalyzerResultsData); //淡出和淡出 $(“#成本分析结果表”).fadeIn(400); } }); } } }, 标记:{ 线宽:1 } } }, 图例:{ 启用:对, 布局:“水平”, 边框宽度:1 }, 系列:[{ 名称:“使用RTI清洗”, 数据:arrhetclean }, { 名称:“未进行RTI清洗”, 数据:arrWithOutClean }] }); } });

}))

好吧,我努力尝试,终于回答了我自己的问题。谢谢你的鼓励!答案在于修改javascript。我一生中从未与js合作过,所以这是第一次

以下是目前正在运行的代码:

$(function () {
$.ajax({
    url: 'PlotCostAnalyzerChart',
    type: "GET",
    dataType: "json",
    success: function (jsonData) {
        $.ajax({
            url: 'GetCumulativeSavings',
            type: 'GET',
            success: function (CumulativeSavingsData) {
                $("#CumulativeSavings").empty();
                $("#CumulativeSavings").html(CumulativeSavingsData);
            },
            error: function (xhr) {
                window.location.href = "/ClientDatabase/Errorview";
            }
        });
        var arrxaxis = new Array();
        var arrWithOutClean = new Array();
        var arrWithClean = new Array();
        for (var i = 0 ; i < jsonData.length ; i++) {
            var mxaxis = new Object();
            var mWithOutClean = new Object();
            var mWithClean = new Object();
            mxaxis = jsonData[i];
            mWithOutClean = jsonData[i];
            mWithClean = jsonData[i];
            arrxaxis.push(mxaxis.Item1);
            arrWithOutClean.push(mWithOutClean.Item2);
            arrWithClean.push(mWithClean.Item3);
        }
        //alert(arr);
        $('#graph_CostAnalyzer').empty();
        $('#graph_CostAnalyzer').highcharts({
            chart: {
                zoomType: 'x'
            },
            title: {
                text: 'Cost Analyzer',
                x: -20 //center
            },
            xAxis: {
                title: {
                    text: 'Number of Weeks'
                }
            },
            yAxis: {
                title: {
                    text: 'Cost of Operations'
                }
            },
            credits: {
                enabled: false
            },
            tooltip: {
                crosshairs: true,
                formatter: function () {
                    return 'Week Number : ' + this.point.x + '<br>' + this.series.name + ' : ' + Highcharts.numberFormat(this.point.y, 2) + '<br>' + 'Click on chart to get cost analysis';
                }

            },
            plotOptions: {
                series: {
                    cursor: 'pointer',
                    point: {
                        events: {
                            click: function (e) {      
                          $("#CostAnalyzerResultsTable").fadeOut(300);
                                $.ajax({
                                    url: 'GetResultsTable',
                                    type: "GET",
                                    data: { weekNumber: this.x },
                                    success: function (CostAnalyzerResultsData) {
                                        //alert(CostAnalyzerResultsData);
                                        $("#CostAnalyzerResultsTable").empty();
                                        $("#CostAnalyzerResultsTable").html(CostAnalyzerResultsData);
                                        //FADEOUT AND FADEIN           
                                        $("#CostAnalyzerResultsTable").fadeIn(400);
                                    }
                                });
                            }
                        }
                    },
                    marker: {
                        lineWidth: 1
                    }
                }
            },
            legend:{
                enabled: true,
                layout: 'horizontal',
                borderWidth: 1
            },                
            series: [{
                name: 'With RTI Cleaning',
                data: arrWithClean,
                pointStart: arrxaxis[0]
            },
            {
                name: 'Without RTI Cleaning',
                data: arrWithOutClean,
                pointStart: arrxaxis[0]
            }]
        });
        }
    });
});
$(函数(){
$.ajax({
url:“PlotCostAnalyzerChart”,
键入:“获取”,
数据类型:“json”,
成功:函数(jsonData){
$.ajax({
url:'GetCumulativeSavings',
键入:“GET”,
成功:功能(累积数据){
$(“#累计设置”).empty();
$(“#CumulativeSavings”).html(CumulativeSavingsData);
},
错误:函数(xhr){
window.location.href=“/ClientDatabase/Errorview”;
}
});
var arrxaxis=新数组();
var arrWithOutClean=新数组();
var arrhithclean=新数组();
对于(var i=0;i