-Build
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
#if !(NET35 || NET20 || PORTABLE || DNXCORE50) || NETSTANDARD1_3 || NETSTANDARD2_0
|
||||
#if !(NET40 || NET35 || NET20 || PORTABLE || DNXCORE50) || NETSTANDARD1_3 || NETSTANDARD2_0
|
||||
#pragma warning disable 618
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
#if !(NET35 || NET20 || PORTABLE || DNXCORE50) || NETSTANDARD1_3 || NETSTANDARD2_0
|
||||
#if !(NET40 || NET35 || NET20 || PORTABLE || DNXCORE50) || NETSTANDARD1_3 || NETSTANDARD2_0
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@@ -50,19 +50,6 @@ using System.Globalization;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation
|
||||
{
|
||||
public class HttpClient
|
||||
{
|
||||
public Task<string> GetStringAsync(string requestUri)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public Task<Stream> GetStreamAsync(string requestUri)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
#region JsonConverterAttribute
|
||||
[JsonConverter(typeof(PersonConverter))]
|
||||
public class Person
|
||||
@@ -134,6 +121,52 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
|
||||
Console.WriteLine(json);
|
||||
}
|
||||
|
||||
public class HttpClient
|
||||
{
|
||||
public Task<Stream> GetStreamAsync(string url)
|
||||
{
|
||||
return Task.FromResult<Stream>(new MemoryStream());
|
||||
}
|
||||
|
||||
public Task<string> GetStringAsync(string url)
|
||||
{
|
||||
return Task.FromResult("{}");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeString()
|
||||
{
|
||||
#region DeserializeString
|
||||
HttpClient client = new HttpClient();
|
||||
|
||||
// read the json into a string
|
||||
// string could potentially be very large and cause memory problems
|
||||
string json = client.GetStringAsync("http://www.test.com/large.json").Result;
|
||||
|
||||
Person p = JsonConvert.DeserializeObject<Person>(json);
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeStream()
|
||||
{
|
||||
#region DeserializeStream
|
||||
HttpClient client = new HttpClient();
|
||||
|
||||
using (Stream s = client.GetStreamAsync("http://www.test.com/large.json").Result)
|
||||
using (StreamReader sr = new StreamReader(s))
|
||||
using (JsonReader reader = new JsonTextReader(sr))
|
||||
{
|
||||
JsonSerializer serializer = new JsonSerializer();
|
||||
|
||||
// read the json from a stream
|
||||
// json size doesn't matter because only a small piece is read at a time from the HTTP request
|
||||
Person p = serializer.Deserialize<Person>(reader);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
public static class PersonWriter
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
#if !(NET35 || NET20 || PORTABLE || DNXCORE50) || NETSTANDARD1_3 || NETSTANDARD2_0
|
||||
#if !(NET40 || NET35 || NET20 || PORTABLE || DNXCORE50) || NETSTANDARD1_3 || NETSTANDARD2_0
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
Reference in New Issue
Block a user