Deserializing large JSON Objects from Web Service (Out of Memory)

后端 未结 1 914
春和景丽
春和景丽 2020-12-21 01:38

I have a program that deserializes large objects from a web service. After a webservice call and a 200, the code looks like this.

JsonConvert.DeserializeObje         


        
相关标签:
1条回答
  • 2020-12-21 01:50
    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);
    }
    
    0 讨论(0)
提交回复
热议问题