JTurk14 JTurk14 - 1 year ago 37
JSON Question

Is it possible to put multiple data types into a JSON file?

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

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?

Answer Source

Sure.

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