如何格式化Response.Write中的字符串?

时间:2015-01-29 13:45:47

标签: javascript c# jquery highcharts

我想使用Highcharts中的此图表,我正在尝试为图表构建数据源。 javascript使用此调用来获取数据源:

$.getJSON('http://localhost:3000/ChartTest.aspx?op=get_data', function (csv) {...}

我使用了chromes console Network并看到Response看起来像这样:

jQuery1102007794869667850435_1422538476833("# ----------------------------------------\n# highcharts.com\n# Audience Overview\n# 20130309-20130408\n# ----------------------------------------\nDay,Visits,Unique Visitors\n3/9/13,5691,4346\n3/10/13,5403,4112\n3/11/13,15574,11356\n3/12/13,16211,11876\n3/13/13,16427,11966\n3/14/13,16486,12086\n3/15/13,14737,10916\n3/16/13,5838,4507\n3/17/13,5542,4202\n3/18/13,15560,11523\n3/19/13,18940,14431\n3/20/13,16970,12599\n3/21/13,17580,13094\n3/22/13,17511,13234\n3/23/13,6601,5213\n3/24/13,6158,4806\n3/25/13,17353,12639\n3/26/13,17660,12768\n3/27/13,16921,12389\n3/28/13,15964,11686\n3/29/13,12028,8891\n3/30/13,5835,4513\n3/31/13,4799,3661\n4/1/13,13037,9503\n4/2/13,16976,12666\n4/3/13,17100,12635\n4/4/13,15701,11394\n4/5/13,14378,10530\n4/6/13,5889,4521\n4/7/13,6779,5109\n4/8/13,16068,11599\n");

所以我试着在我自己的页面中写这样:

public partial class ChartTest : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["op"] == "get_data")
        {
            Response.Clear();
            Response.Write("\"Day,Visits,Unique Visitors\n3/9/13,5691,4346\n3/10/13,5403,4112\n3/11/13,15574,11356\n3/12/13,16211,11876\n3/13/13,16427,11966\n3/14/13,16486,12086\n3/15/13,14737,10916\n3/16/13,5838,4507\n3/17/13,5542,4202\n3/18/13,15560,11523\n3/19/13,18940,14431\n3/20/13,16970,12599\n3/21/13,17580,13094\n3/22/13,17511,13234\n3/23/13,6601,5213\n3/24/13,6158,4806\n3/25/13,17353,12639\n3/26/13,17660,12768\n3/27/13,16921,12389\n3/28/13,15964,11686\n3/29/13,12028,8891\n3/30/13,5835,4513\n3/31/13,4799,3661\n4/1/13,13037,9503\n4/2/13,16976,12666\n4/3/13,17100,12635\n4/4/13,15701,11394\n4/5/13,14378,10530\n4/6/13,5889,4521\n4/7/13,6779,5109\n4/8/13,16068,11599\n\"");
            Response.Flush();
        }
    }
}

但我从我的网址看到的响应看起来像是:

Day,Visits,Unique Visitors
3/9/13,5691,4346
3/10/13,5403,4112
3/11/13,15574,11356
3/12/13,16211,11876
3/13/13,16427,11966
3/14/13,16486,12086
3/15/13,14737,10916
3/16/13,5838,4507
3/17/13,5542,4202
3/18/13,15560,11523
3/19/13,18940,14431
3/20/13,16970,12599
3/21/13,17580,13094
3/22/13,17511,13234
3/23/13,6601,5213
3/24/13,6158,4806
3/25/13,17353,12639
3/26/13,17660,12768
3/27/13,16921,12389
3/28/13,15964,11686
3/29/13,12028,8891
3/30/13,5835,4513
3/31/13,4799,3661
4/1/13,13037,9503
4/2/13,16976,12666
4/3/13,17100,12635
4/4/13,15701,11394
4/5/13,14378,10530
4/6/13,5889,4521
4/7/13,6779,5109
4/8/13,16068,11599

因为图表没有显示... 我怎样才能使我的回复与上面的回复相同/或者对图表加载有利的东西......?

1 个答案:

答案 0 :(得分:0)

看起来我需要做的就是将\ n更改为\ n并添加"像这样:

Response.Write("\"Day,Visits,Unique Visitors\\n3/9/13,5691,4346\\n3/10/13,5403,4112\\n3/11/13,15574,11356\\n3/12/13,16211,11876\\n3/13/13,16427,11966\\n3/14/13,16486,12086\\n3/15/13,14737,10916\\n3/16/13,5838,4507\\n3/17/13,5542,4202\\n3/18/13,15560,11523\\n3/19/13,18940,14431\\n3/20/13,16970,12599\\n3/21/13,17580,13094\\n3/22/13,17511,13234\\n3/23/13,6601,5213\\n3/24/13,6158,4806\\n3/25/13,17353,12639\\n3/26/13,17660,12768\\n3/27/13,16921,12389\\n3/28/13,15964,11686\\n3/29/13,12028,8891\\n3/30/13,5835,4513\\n3/31/13,4799,3661\\n4/1/13,13037,9503\\n4/2/13,16976,12666\\n4/3/13,17100,12635\\n4/4/13,15701,11394\\n4/5/13,14378,10530\\n4/6/13,5889,4521\\n4/7/13,6779,5109\\n4/8/13,16068,11599\\n\"");