我有一个流产生以下类似json的数据:
{
"type": "TypeA",
"time": "2018-04-18T19:54:06.653874823Z",
"status": "Pending"
}
{
"type": "TypeB",
"time": "2018-04-18T19:55:06.653874823Z",
"status": "Pending"
}
{
...
我想用JSON.Net将它绑定到我的班级
public class MyData
{
public string Type { get; set; }
public string Time { get; set; }
public string Status { get; set; }
}
如果正在流式传输的数据格式正确,则为json,即
[
{
"type": "TypeA",
"time": "2018-04-18T19:54:06.653874823Z",
"status": "Pending"
},
{
"type": "TypeB",
"time": "2018-04-18T19:55:06.653874823Z",
"status": "Pending"
},
{
...
]
我可以通过
简单地实现这一目标var serializer = new JsonSerializer();
using (var sr = new StreamReader(myStream)
using (var reader = new JsonTextReader(sr))
{
var myDatas= serializer.Deserialize<List<MyData>>(reader);
}
有没有办法配置JSON.Net来使用上面显示的类似json的数据?或者,在让JSON.Net进行转换之前,我是否必须转换数据?