Json.net JsonSchema C#

Json.net JsonSchema C#,c#,json.net,jsonschema,C#,Json.net,Jsonschema,我试图解析一个模式并从中读取一个元素,但是我得到了一个错误 这是我的代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.IO; using Newtonsoft.Json.Schema; namespace ConsoleApplication1 { class Test {

我试图解析一个模式并从中读取一个元素,但是我得到了一个错误

这是我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.IO;
using Newtonsoft.Json.Schema;

namespace ConsoleApplication1
{
    class Test
    {
        static void Main(string[] args)
        {

            string ingameschemaFilePath = @"C:\Users\Andrew\Documents\GitHub\SteamBot\Bin\Debug\ingameschema.txt";
            string dota2schemaFilePath = @"C:\Users\Andrew\Documents\GitHub\SteamBot\Bin\Debug\dota2schema.txt";
            string schemaFilePath = @"C:\Users\Andrew\Documents\GitHub\SteamBot\Bin\Debug\schema.txt";

            JsonSchema dota2schema = JsonSchema.Parse(File.ReadAllText(dota2schemaFilePath));

            Console.WriteLine(dota2schema.result.items.name);

            System.Console.WriteLine("Press any key to exit.");
            System.Console.ReadKey();
        }
    }

}
这就是我得到的错误:

Error   2   'Newtonsoft.Json.Schema.JsonSchema' does not contain a definition for 'result' and no extension method 'result' accepting a first argument of type 'Newtonsoft.Json.Schema.JsonSchema' could be found (are you missing a using directive or an assembly reference?)
我在这里尝试按照示例进行操作:

示例->JsonSchema->解析Json模式

下面是我试图阅读的模式的开始:

{
    "result": {
        "status": 1,
        "items_game_url": "http:\/\/media.steampowered.com\/apps\/570\/scripts\/items\/items_game.d8ab2f9911cea9d7f4bce1add62c7bb83a902322.txt",
        "qualities": {
            "normal": 0,
            "genuine": 1,
            "vintage": 2,
            "unusual": 3,
            "unique": 4,
            "community": 5,
            "developer": 6,
            "selfmade": 7,
            "customized": 8,
            "strange": 9,
            "completed": 10,
            "haunted": 11,
            "tournament": 12,
            "favored": 13
        },
        "originNames": [
            {
                "origin": 0,
                "name": "Timed Drop"
            },
            {
                "origin": 1,
                "name": "Achievement"
            },
            {
                "origin": 2,
                "name": "Purchased"
            },
            {
                "origin": 3,
                "name": "Traded"
            },
            {
                "origin": 4,
                "name": "Crafted"
            },
            {
                "origin": 5,
                "name": "Store Promotion"
            },
            {
                "origin": 6,
                "name": "Gifted"
            },
            {
                "origin": 7,
                "name": "Support Granted"
            },
            {
                "origin": 8,
                "name": "Found in Crate"
            },
            {
                "origin": 9,
                "name": "Earned"
            },
            {
                "origin": 10,
                "name": "Third-Party Promotion"
            },
            {
                "origin": 11,
                "name": "Wrapped Gift"
            },
            {
                "origin": 12,
                "name": "Halloween Drop"
            },
            {
                "origin": 13,
                "name": "Steam Purchase"
            },
            {
                "origin": 14,
                "name": "Foreign Item"
            },
            {
                "origin": 15,
                "name": "CD Key"
            },
            {
                "origin": 16,
                "name": "Collection Reward"
            },
            {
                "origin": 17,
                "name": "Preview Item"
            },
            {
                "origin": 18,
                "name": "Steam Workshop Contribution"
            },
            {
                "origin": 19,
                "name": "Periodic Score Reward"
            },
            {
                "origin": 20,
                "name": "Recycling"
            },
            {
                "origin": 21,
                "name": "Tournament Drop"
            },
            {
                "origin": 22,
                "name": "Passport Reward"
            },
            {
                "origin": 23,
                "name": "Tutorial Drop"
            }
        ]
        ,
        "items": [
            {
                "name": "Riki's Dagger",
                "defindex": 0,
                "item_class": "dota_item_wearable",
                "item_type_name": "#DOTA_WearableType_Daggers",
                "item_name": "#DOTA_Item_Rikis_Dagger",
                "proper_name": false,
                "item_quality": 0,
                "image_inventory": null,
                "min_ilevel": 1,
                "max_ilevel": 1,
                "image_url": "",
                "image_url_large": "",
                "capabilities": {
                    "can_craft_mark": true,
                    "can_be_restored": true,
                    "strange_parts": true,
                    "paintable_unusual": true,
                    "autograph": true

我想我做的和样品做的差不多。我做错了什么?我寻找过类似的问题,但没有找到答案。另外,如果您能让我知道从json模式中获取“Riki's Dagger”的Def索引的正确方法,那就太好了。

如果您想从json中读取元素

  • 使用or从JSON生成类(我觉得这样更好)

  • 使用JSON.net将JSON反序列化为根类

    var ouput -JsonConvert.Deserialize<your_root_class>(JSONString);
    
    var-output-JsonConvert.Deserialize(JSONString);
    
  • 只需读取您想要的值