我在解析大约1GB的JSON文件时遇到问题。当我运行以下代码时,我得到一个内存不足的例外:
using (FileStream sr = new FileStream("myFile.json", FileMode.Open, FileAccess.Read))
{
using (StreamReader reader = new StreamReader(sr))
{
using (JsonReader jsReader = new JsonTextReader(reader))
{
JsonSerializer serializer = new JsonSerializer();
dataObject = serializer.Deserialize<T>(jsReader);
}
}
}
抛出异常
Newtonsoft.Json.Linq.JTokenWriter.WriteValue(Int64 value)
序列化效果很好,这是我使用
的代码using (StreamWriter reader = new StreamWriter("myFile.json"))
{
using (JsonReader jsWriter = new JsonWriter(reader))
{
JsonTextWriter jsonWriter = new JsonTextWriter(jsWriter) { Formatting = Formatting.Indented };
JsonSerializer ser = new JsonSerializer();
ser.Serialize(jsonWriter, dataObject, dataObject.GetType());
jsonWriter.Flush();
}
}}
我在反序列化中做错了吗?你能帮忙建议一种反序列化大json对象的方法吗?
由于