I am using the Json.NET library. What is the most convenient way to serialize / deserialize arrays in JSON via C #? For example, I am trying to deserialize the following text (reading from a file):
{ "Name": "Christina", "Gender": "female", "Favorite_numbers": [11, 25 ,23] }
I am reading the text above from a file into a variable:
JObject o = JObject.Parse(File.ReadAllText("input.txt"))
And then when I try to extract an array [11, 24, 23] using
int[] num = (int[]) o["Favorite_numbers"]
I get an error message.
What am I doing wrong? How to read an array correctly? How to read 2-dimensional arrays of the following form [[1, 2, 3], [4, 5, 6]] ?
user217905
source share