我在将数字的JSON列表读取到ac#int []数组时遇到麻烦。
我尝试了SO的一些建议,但没有一个起作用。我将如何使用JSON.net进行此操作?
从JSON文件中提取:
{
"course": "Norsk",
"grades": [6, 3, 5, 6, 2, 8]
}
Run Code Online (Sandbox Code Playgroud)
我在c#中尝试过的内容:
// Reads the JSON file into a single string
string json = File.ReadAllText(jfile);
Console.WriteLine(json);
// Parsing the information to a format json.net can work with
JObject data = JObject.Parse(json);
JToken jToken = data.GetValue("grades");
jGrades = jToken.Values<int>().ToArray();
Run Code Online (Sandbox Code Playgroud)
和:
// Reads the JSON file into a single string
string json = File.ReadAllText(jfile);
Console.WriteLine(json);
// Parsing the information to a format json.net can work with
JObject data …Run Code Online (Sandbox Code Playgroud)