File.ReadAllText()导致错误 - 路径中的字符非法

时间:2016-07-20 21:18:26

标签: c#

我最终发现了我的代码问题。

我的代码在以下点断开String vehicle = File.ReadAllText(result); 错误消息 - 路径中的非法字符。

不确定如何修复此任何帮助非常感谢,完整代码如下;

  //Get Response
        var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
        using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
        {
            //Here you got the JSON as string:
            var result = streamReader.ReadToEnd();
            **String vehicle = File.ReadAllText(result);**

            // Write the text to a new file named "Response.json".
            var fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Respone.json");
            File.WriteAllText(fileName, result);
        }
    }

1 个答案:

答案 0 :(得分:0)

原因<script src="https://code.highcharts.com/highcharts.js"></script> <script src="https://code.highcharts.com/highcharts-more.js"></script> <script src="https://code.highcharts.com/modules/exporting.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> <div id="adaRate"></div> $(function() { var options = { chart: { renderTo: 'adaRate', type: 'bar', width: 600, height: 400 }, title: { text: 'Average Daily Attendance Rate', align: 'center', style: { fontWeight: 'bold', color: 'rgba(0,0,0,.9)' } }, legend: { enabled: true }, tooltip: { shared: true, crosshairs: true, formatter: function() { var s = '<b>' + this.x + '</b>'; $.each(this.points, function() { s += '<br/>' + this.series.name + ': ' + this.y + '%'; }); return s; }, }, xAxis: { labels: { style: { fontWeight: 'bold' } } }, yAxis: [{ min: 0, max: 100, opposite: true, width: 270, title: { text: 'Average Daily Attendance %' } }, { min: -10, max: 10, offset: 0, opposite: true, plotLines: [{ color: 'red', value: 0, width: 2 }], left: 400, width: 170, title: { text: 'Variance from Prior Year' } }], series: [{ name: 'ADA', dataLabels: { enabled: true, align: 'right', color: '#FFFFFF', x: -10 }, yAxis: 0, }, { type: 'scatter', name: 'PY Variance', dataLabels: { enabled: true, align: 'center', color: '#000000', x: -10 }, yAxis: 1, }], credits: { enabled: false } }; var categories = ["School 1", "School 2", "School 3", "School 4", "School 5", "School 6", "School 7"]; var adaRate = [96.4, 95.9, 93.3, 92.3, 89.8, 85.4, 83.9]; var adaVar = [{ "color": "yellow", "y": -.8 }, { "color": "red", "y": -3.5 }, { "color": "lightgreen", "y": 1.5 }, { "color": "lightgreen", "y": 2.3 }, { "color": "red", "y": -4.3 }, { "color": "green", "y": 5.3 }, { "color": "darkgreen", "y": 7.8 } ]; options.xAxis.categories = categories; options.series[0].data = adaRate; options.series[1].data = adaVar; var chart = new Highcharts.Chart(options); }); 排除了您要阅读的文件路径,而不是您从File.ReadAllText()获取的文件内容

下面的代码行对我来说是多余的,因为streamReader.ReadToEnd()无论如何都会为您提供内容。

var result = streamReader.ReadToEnd();