小编Hag*_*and的帖子

将JSON列表解析为C#中的int数组

我在将数字的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)

c# json.net

0
推荐指数
1
解决办法
3543
查看次数

标签 统计

c# ×1

json.net ×1