Ejemplo n.º 1
0
        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
        }
Ejemplo n.º 2
0
        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
        }