我想从硬盘(它有14mb)中保存中等大小的JSON文件。我找到了简单的方法:
public static void Load(string path = CacheFilePath)
{
path = Path.GetFullPath(path);
if (!File.Exists(path))
return;
JsonSerializer serializer = new JsonSerializer();
using (FileStream s = File.Open(path, FileMode.Open))
using (StreamReader sr = new StreamReader(s))
using (JsonReader red = new JsonTextReader(sr))
{
while (red.Read())
{
JObject Data = serializer.Deserialize<JObject>(red);
}
}
}
一切正常,但是,这个JObject需要近360mb的RAM。可以设置任何JSON设置来减小此值吗?
还是还有另一种将数据作为JSON保留在内存中的方法?
快速查看文件(例如,真实文件大约有230 k):
{
"OrderValidationData":
{
"Count":2,
"Name":"OrderValidationData",
"Keys":[
"WAL22999-96",
"HEL5DA 193 175-111",
**n**
],
"Data":
{
"WAL22999-96":
{
"MinimalNetPrice":10.00,
"VatRate":12.00
},
"HEL5DA 193 175-111":
{
"MinimalNetPrice":10.00,
"VatRate":12.00
}
, **{n}**
}
}
}