我正在尝试读取一个外部json以在屏幕上显示数据。我在这儿干什么?
public void QuarterlyReport(object sender, EventArgs e)
{
JObject qData1 = JObject.Parse(System.IO.File.ReadAllText(@"~/json/quarterlyData.json"));
// read JSON directly from a file
using (StreamReader file = System.IO.File.OpenText(@"~/json/quarterlyData.json"))
using (JsonTextReader reader = new JsonTextReader(file))
{
JObject Qdata2 = (JObject) JToken.ReadFrom(reader);
}
string Qdata = Newtonsoft.Json.JsonConvert.SerializeObject(qData1);
}
public async Task<FileStreamResult> Index()
{
var _reportingService = new ReportingService("https://mysite.jsreportonline.net", "myemail@gmail.com", "password");
var report = await _reportingService.RenderAsync("VyxOYwH7Ze", new { Qdata });
//add the stream to be used by browser
MemoryStream ms = new MemoryStream();
//copy whatever JS is sending to us
report.Content.CopyTo(ms);
//start at content point
ms.Position = 0;
//send this to browser
return File(ms, report.ContentType.MediaType);
}
我似乎无法将变量Qdata带入其中。我在方法上做错了什么?
声明Qdata的行:
string Qdata = Newtonsoft.Json.JsonConvert.SerializeObject(qData1);
与此行不在同一范围内:
var report = await _reportingService.RenderAsync("VyxOYwH7Ze", new { Qdata });
是的,问题是
JObject qData1 = JObject.Parse(System.IO.File.ReadAllText(@"~/json/quarterlyData.json"));
和
string Qdata = Newtonsoft.Json.JsonConvert.SerializeObject(qData1);
需要与在同一范围内
var report = await _reportingService.RenderAsync("VyxOYwH7Ze", new { Qdata });