我正在使用JSON.NET和C#5.我需要将对象列表序列化/反序列化为行分隔的json.http://en.wikipedia.org/wiki/Line_Delimited_JSON.例,
{"some":"thing1"}
{"some":"thing2"}
{"some":"thing3"}
Run Code Online (Sandbox Code Playgroud)
和
{"kind": "person", "fullName": "John Doe", "age": 22, "gender": "Male", "citiesLived": [{ "place": "Seattle", "numberOfYears": 5}, {"place": "Stockholm", "numberOfYears": 6}]}
{"kind": "person", "fullName": "Jane Austen", "age": 24, "gender": "Female", "citiesLived": [{"place": "Los Angeles", "numberOfYears": 2}, {"place": "Tokyo", "numberOfYears": 2}]}
Run Code Online (Sandbox Code Playgroud)
我需要的原因是因为其Google BigQuery要求https://cloud.google.com/bigquery/preparing-data-for-bigquery
更新:我找到的一种方法是将每个对象序列化为seperataly并最后用new-line连接.
我试图用来MessagePack保存多个结构列表,因为我读到它的性能比BinaryFormatter序列化更好。
我想要做的是接收实时时间序列数据并定期将其保存(附加)到磁盘上,例如,如果列表的元素数为 100。我的问题是:
1)在这种情况下,序列化结构列表并将其异步保存到磁盘是否更好?
2) 如何使用 MessagePack 简单地将其保存到磁盘?
public struct struct_realTime
{
public int indexNum { get; set; }
public string currentTime { get; set; }
public string currentType { get; set; }
}
class Program
{
static void Main(string[] args)
{
List<struct_realTime> list_temp = new List<struct_realTime>(100000);
for (int num=0; num < 100000; num++)
{
list_temp.Add(new struct_realTime
{
indexNum = 1,
currentTime = "time",
currentType = "type",
});
}
string filename = "file.bin";
using (var fileStream …Run Code Online (Sandbox Code Playgroud) 我正在尝试保存压力图的流数据.基本上我有一个压力矩阵定义为:
double[,] pressureMatrix = new double[e.Data.GetLength(0), e.Data.GetLength(1)];
Run Code Online (Sandbox Code Playgroud)
基本上,我pressureMatrix每10毫秒得到一个,我想将所有信息保存在JSON文件中,以便以后能够重现它.
我所做的是,首先,写下我称之为标题的标题,其中包含用于录制的所有设置,如下所示:
recordedData.softwareVersion = Assembly.GetExecutingAssembly().GetName().Version.Major.ToString() + "." + Assembly.GetExecutingAssembly().GetName().Version.Minor.ToString();
recordedData.calibrationConfiguration = calibrationConfiguration;
recordedData.representationConfiguration = representationSettings;
recordedData.pressureData = new List<PressureMap>();
var json = JsonConvert.SerializeObject(csvRecordedData, Formatting.None);
File.WriteAllText(this.filePath, json);
Run Code Online (Sandbox Code Playgroud)
然后,每次我得到一个新的压力图我创建一个新的线程来添加新的PressureMatrix并重新写入该文件:
var newPressureMatrix = new PressureMap(datos, DateTime.Now);
recordedData.pressureData.Add(newPressureMatrix);
var json = JsonConvert.SerializeObject(recordedData, Formatting.None);
File.WriteAllText(this.filePath, json);
Run Code Online (Sandbox Code Playgroud)
大约20-30分钟后,我得到一个OutOfMemory异常,因为系统无法保存recordedData var,因为List<PressureMatrix>它太大了.
如何处理这个以保存数据?我想保存24-48小时的信息.