是否可以将多种数据类型放入JSON文件中?

时间:2022-02-26 17:22:22

I am serializing and writing an Object List into a JSON file with this C# code:

我正在使用此C#代码序列化并将对象列表写入JSON文件:

string json = JsonConvert.SerializeObject(drawList);
File.WriteAllText(@"C:\my\sample\path\package.json", json);

Is it possible to also write an integer into this json file, and if so how should it be parsed so that the list and integer are separate?

是否有可能在这个json文件中写一个整数,如果是这样,应该如何解析它以使列表和整数分开?

1 个解决方案

#1


2  

Sure.

当然。

string json = JsonConvert.SerializeObject(new {integer = 1, list = drawList});
File.WriteAllText(@"C:\my\sample\path\package.json", json);

#1


2  

Sure.

当然。

string json = JsonConvert.SerializeObject(new {integer = 1, list = drawList});
File.WriteAllText(@"C:\my\sample\path\package.json", json);