我有一个非常非常大的JSON文件(1000+ MB)相同的JSON对象.例如:
[
{
"id": 1,
"value": "hello",
"another_value": "world",
"value_obj": {
"name": "obj1"
},
"value_list": [
1,
2,
3
]
},
{
"id": 2,
"value": "foo",
"another_value": "bar",
"value_obj": {
"name": "obj2"
},
"value_list": [
4,
5,
6
]
},
{
"id": 3,
"value": "a",
"another_value": "b",
"value_obj": {
"name": "obj3"
},
"value_list": [
7,
8,
9
]
},
...
]
Run Code Online (Sandbox Code Playgroud)
根JSON列表中的每个项都遵循相同的结构,因此可以单独反序列化.我已经编写了C#类来接收这些数据,并且反序列化包含单个对象的JSON文件而没有列表按预期工作.
起初,我试图在循环中直接反序列化我的对象:
JsonSerializer serializer = new JsonSerializer();
MyObject o;
using (FileStream s = File.Open("bigfile.json", FileMode.Open))
using (StreamReader sr …Run Code Online (Sandbox Code Playgroud)