从webservice返回JSON数据

时间:2017-03-01 07:49:50

标签: c# asp.net json webmethod

我正在尝试从Web服务获取JSON数据。 以下是Webservice的代码:

[WebMethod]
        [System.Xml.Serialization.XmlInclude(typeof(Object[]))]
        public List<Dashboard_design.Pages.chartClass.chartData> getLineChartData()
        {
            var ChartDataList = new List<chartClass.chartData>();

            var chrtObj = new chartClass.chartData();

            var query_DataSet_1 = @"Select * From (SELECT
            DYYYY, DMM, DDD, DTIME,
            avg(case when MID IN(31950) then V else null end) Val_2
            FROM(
            SELECT
              TO_CHAR(DATAPOINT_DATETIME, 'YYYY') DYYYY,
              TO_CHAR(DATAPOINT_DATETIME, 'MM') DMM,
              TO_CHAR(DATAPOINT_DATETIME, 'DD') DDD,
              TO_CHAR(DATAPOINT_DATETIME, 'HH24:MI:SS') DTIME,
              DATAPOINT_VALUE V, D.DATAPOINT_ID I, Measurement_ID MID
            FROM
              Datapoints D
            WHERE
              Measurement_ID IN(31950, 31951, 31952, 31953, 31954, 31955, 31956, 31957, 31958, 713504, 31959, 31960, 31961, 31962, 31963, 31964, 31965, 31966, 31967, 31968, 31969, 31970)
              and D.DATAPOINT_DATETIME > TO_DATE('01.01.1900 00:00:00', 'DD.MM.YYYY HH24:MI:SS')

              and D.DATAPOINT_DATETIME < TO_DATE('31.12.2099 23:59:59', 'DD.MM.YYYY HH24:MI:SS')
            ) GROUP BY DYYYY,DMM,DDD,DTIME ORDER BY DYYYY DESC ,DMM DESC, DDD DESC ,DTIME DESC ) where rownum <= 1000;";


            var dtDataItemsSets_1 = GetDataset(query_DataSet_1);

            foreach (DataRow dr in dtDataItemsSets_1.Rows)
            {
                if (dr[4].ToString() != "" || dr[4]!=null)
                {
                    var xval = dr[2].ToString() + "-" + dr[1].ToString() + "-" + dr[0].ToString();

                    chrtObj.xValue = xval;
                    chrtObj.yValue = dr[4].ToString();

                    ChartDataList.Add(chrtObj);
                }
            }

            JavaScriptSerializer js = new JavaScriptSerializer();
            Context.Response.Write(js.Serialize(ChartDataList));


            return ChartDataList;
        }

当我运行这个webmethod时,我收到了以下错误。

enter image description here

可以告诉我,我在哪里错了。

注意:我可以从上面的代码中获取xml数据(通过删除JavaScriptSerializer)。但不是JSON。

0 个答案:

没有答案