本文整理汇总了C#中System.IO.StreamReader.FromJson方法的典型用法代码示例。如果您正苦于以下问题:C# StreamReader.FromJson方法的具体用法?C# StreamReader.FromJson怎么用?C# StreamReader.FromJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StreamReader
的用法示例。
在下文中一共展示了StreamReader.FromJson方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FixtureCreate
public Stream FixtureCreate(Stream fixtureStream)
{
//Get JSON string from stream
var fixtureJson = new StreamReader(fixtureStream).ReadToEnd();
//Deserialize
var contentType = HttpContext.Current.Request.ContentType;
var fixture = fixtureJson.FromJson<Fixture>(contentType);
//Store in Mongo DB
var createdFixture = CreateFixture(fixture);
createdFixture.Id = null;
//Serialize
var createdFixtureJson = createdFixture.ToJson();
var createdFixtureJsonBytes = Encoding.UTF8.GetBytes(createdFixtureJson);
var createdFixtureJsonMemoryStream = new MemoryStream(createdFixtureJsonBytes);
return createdFixtureJsonMemoryStream;
}
示例2: FixtureCreate
public Stream FixtureCreate(Stream fixtureStream)
{
//Get JSON string from stream
var fixtureJson = new StreamReader(fixtureStream).ReadToEnd();
//Deserialize
var contentType = HttpContext.Current.Request.ContentType;
var fixture = fixtureJson.FromJson<Fixture>(contentType);
//Call Internal Service to Store
const string fixtureCreateUrl = InternalServiceUrl + "fixture";
var fixtureCreateJson = fixture.ToJson();
var createdFixtureJson = RestHelper.GetJsonResponse(new Uri(fixtureCreateUrl), fixtureCreateJson, "POST", contentType);
//Return
var createdFixtureJsonBytes = Encoding.UTF8.GetBytes(createdFixtureJson);
var createdFixtureJsonMemoryStream = new MemoryStream(createdFixtureJsonBytes);
return createdFixtureJsonMemoryStream;
}
示例3: bWebHttp_Click
private void bWebHttp_Click(object sender, EventArgs e)
{
try
{
sw.Reset();
sw.Start();
WebRequest request = WebRequest.Create("http://localhost:8000/DesktopService/c/20");
WebResponse ws = request.GetResponse();
var d = new StreamReader(ws.GetResponseStream(), true).ReadToEnd().UrlDecode();
//var s = ws.GetResponseStream().Read()
//var s = d.Substring(1, s.Length - 2);
var r = d.FromJson<ServiceResult>();
var s = r.Result.ToString();
//File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "c.txt", s);
sw.Stop();
box.Text += "GetData returned {0} bytes and costed {1} ms\r\n".Fmt(s.Length,
sw.ElapsedMilliseconds);
byte[] bs = Convert.FromBase64String(s);
using (MemoryStream ms = new MemoryStream(bs))
{
var bmp = Image.FromStream(ms);
pic.Image = bmp;
}
}
catch (Exception ex)
{
Error.Handle(ex);
}
}